Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not working on android #3

Open
iambavith-dev opened this issue Jul 30, 2023 · 0 comments
Open

Not working on android #3

iambavith-dev opened this issue Jul 30, 2023 · 0 comments

Comments

@iambavith-dev
Copy link

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());
    }
    }
    `
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant