Skip to content

Not working on android  #3

@iambavith-dev

Description

@iambavith-dev

package.json

  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.72.3",
    "react-native-dynamic-bundle-restore": "^0.7.4",
    "react-native-fs": "^2.20.0",
    "rn-fetch-blob": "^0.12.0"
  },

MainApplication.java

`package com.autoupdate;

import android.app.Application;
import com.facebook.react.PackageList;
import com.facebook.react.ReactApplication;
import com.facebook.react.ReactNativeHost;
import com.facebook.react.ReactPackage;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactNativeHost;
import com.facebook.soloader.SoLoader;
import java.util.List;
import org.killserver.reactnativedynamicbundlerestore.RNDynamicBundleModule;
import org.killserver.reactnativedynamicbundlerestore.RNDynamicBundlePackage;

public class MainApplication extends Application implements ReactApplication {

private final ReactNativeHost mReactNativeHost =
new DefaultReactNativeHost(this) {
@OverRide
public boolean getUseDeveloperSupport() {
return BuildConfig.DEBUG;
}

    @Override
    protected List<ReactPackage> getPackages() {
      @SuppressWarnings("UnnecessaryLocalVariable")
      List<ReactPackage> packages = new PackageList(this).getPackages();
      // Packages that cannot be autolinked yet can be added manually here, for example:
      // packages.add(new MyReactNativePackage());
      packages.add(new RNDynamicBundlePackage());
      return packages;
    }

    @Override
    protected String getJSMainModuleName() {
      return "index";
    }

    @Nullable
    @Override
    protected String getJSBundleFile() {
      return RNDynamicBundleModule.launchResolveBundlePath(MainApplication.this);
    }

    @Override
    protected boolean isNewArchEnabled() {
      return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED;
    }

    @Override
    protected Boolean isHermesEnabled() {
      return BuildConfig.IS_HERMES_ENABLED;
    }
  };

@OverRide
public ReactNativeHost getReactNativeHost() {
return mReactNativeHost;
}

@OverRide
public void onCreate() {
super.onCreate();
SoLoader.init(this, /* native exopackage */ false);
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
DefaultNewArchitectureEntryPoint.load();
}
ReactNativeFlipper.initializeFlipper(this, getReactNativeHost().getReactInstanceManager());
}
}
`

MainActivity.java

`package com.autoupdate;

import com.facebook.react.ReactActivity;
import com.facebook.react.ReactActivityDelegate;
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
import com.facebook.react.defaults.DefaultReactActivityDelegate;

import com.facebook.react.ReactInstanceManager;
import com.facebook.react.bridge.ReactContext;

import org.killserver.reactnativedynamicbundlerestore.RNDynamicBundleModule;

public class MainActivity extends ReactActivity implements RNDynamicBundleModule.OnReloadRequestedListener {

private RNDynamicBundleModule module;

@OverRide
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

    MainApplication app = (MainApplication)this.getApplicationContext();
    app.getReactNativeHost().getReactInstanceManager().addReactInstanceEventListener(new ReactInstanceManager.ReactInstanceEventListener() {
        @Override
        public void onReactContextInitialized(ReactContext context) {
            MainActivity.this.module = context.getNativeModule(RNDynamicBundleModule.class);
            module.setListener(MainActivity.this);
        }
    });
}

/**

  • Returns the name of the main component registered from JavaScript. This is used to schedule
  • rendering of the component.
    */
    @OverRide
    protected String getMainComponentName() {
    return "autoupdate";
    }

/**

  • Returns the instance of the {@link ReactActivityDelegate}. Here we use a util class {@link
  • DefaultReactActivityDelegate} which allows you to easily enable Fabric and Concurrent React
  • (aka React 18) with two boolean flags.
    */
    @OverRide
    protected ReactActivityDelegate createReactActivityDelegate() {
    return new DefaultReactActivityDelegate(
    this,
    getMainComponentName(),
    // If you opted-in for the New Architecture, we enable the Fabric Renderer.
    DefaultNewArchitectureEntryPoint.getFabricEnabled());
    }
    }
    `

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions