Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use multiple ReactNativeHosts for CodePush within one Application?

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.

like image 799
K. D. Avatar asked Mar 08 '26 12:03

K. D.


1 Answers

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!

like image 50
Geoffrey Goh Avatar answered Mar 10 '26 01:03

Geoffrey Goh