3

I want to integrate React Native based modules to my existing Android application. This works quite nice so far but I also want to integrate CodePush to deploy updates to my application.

The important point is that the modules should be independent from the specific application because I have multiple different applications that should use those modules. So the modules themselves are independent React Native packages and so they must be separate Code-Push applications (I guess).

Currently such an React Native module (implemented as a Fragment) is working like this:

public class ReactFragment extends Fragment {

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
        ReactRootView mReactRootView = new ReactRootView(getContext());
        ReactInstanceManager mReactInstanceManager = ReactInstanceManager.builder()
                .setApplication(getActivity().getApplication())
                .setBundleAssetName("index.android.bundle")
                .setJSMainModuleName("index.android")
                .addPackage(new MainReactPackage())
                .setUseDeveloperSupport(false)
                .setInitialLifecycleState(LifecycleState.RESUMED)
                .build();
        mReactRootView.startReactApplication(mReactInstanceManager, "HelloWorld", null);
        return mReactRootView;
    }
}

So following the official CodePush guide I have no idea how to use multiple CodePush projects within the same Android application. However I think that there must be something within my onCreateView that allows me to inject the CodePush package or at least a custom ReactNativeHost.

K. D.
  • 4,041
  • 9
  • 48
  • 72

1 Answers1

5

That's an interesting scenario that is not supported (yet) by the React Native CodePush SDK (without custom code to modify it). Specifically, we need a way to save CodePush provided lupdates on disk in separate locations for each ReactNativeHost. Right now, it's a single hard coded location https://github.com/Microsoft/react-native-code-push/blob/master/android/app/src/main/java/com/microsoft/codepush/react/CodePushUpdateManager.java#L40. While it's in our backlog, this scenario might not get prioritized too quickly, but it also looks like it could be not too hard a change to make, so if you would like to delve into the code and make the change yourself, feel free to send out a pull request. Otherwise, you could also file an enhancement issue on our repo so we can track it. Thanks for the feedback!

Geoffrey Goh
  • 233
  • 1
  • 7
  • Any progress in this direction so far? The scenario is very interesting indeed, and many developers who involved in creation of multi-modular React Native constructions impatiently look for any solution. Thanks! – stone Jan 09 '23 at 11:55