6

For my Android app, I need to be able to dynamically update the Bundle at runtime and use the pre-saved bundle in my Assets as a fall back. I have failed to find any information on this in the Official Documentation.

In the iOS version of react native, there is a method that lets you specify a URL from which to load the JS bundle, but I have yet to see an equivalent option for Android. How is this possible for Android?

Update It looks like the RN team has been working on this very feature and will be part of the next release: https://github.com/facebook/react-native/commit/3a743ef228a14e07c77c5488b080413643ec9c4b

0

2 Answers 2

6

1.download bundle file(s) and manage the path(s).

2.new a ReactNativeHost in your Application:

public String mBundleFilePath = "";
private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
        return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
        return Arrays.asList(new MainReactPackage(), new MyReactPackage());
    }

    @Override
    protected String getJSBundleFile() {
        return mBundleFilePath;
    }
};

3.before starting a ReactActivity, assign the path of ur bundle file to variable: mBundleFilePath.

public class ReactNativeActivity extends ReactActivity {
    public static void launchSelf(...) {
        MyApplication.getInstance().mBundleFilePath = path;
        COMPONENT_NAME = ...;
        Intent intent = new Intent(activity,ReactNativeActivity.class);
        activity.startActivity(..);
    }
    ...
}

source code:

com.facebook.react.ReactNativeHost#createReactInstanceManager
com.facebook.react.ReactInstanceManager.Builder#setJSBundleFile
com.facebook.react.cxxbridge.JSBundleLoader#createFileLoader

...

may it help u : )

Sign up to request clarification or add additional context in comments.

3 Comments

Am able to download and set the bundle but none of the images are displayed and same is working fine If I set the bundle from asset folder
I am facing the same issue images are not loaded i knwe this is old question but any hint on how to make the images show is highly appreciated.My RN version is 0.51
probably because you should use your own image loader or use external images (i.e. from the cloud).
3

Yes, it's possible. you can give Code Push a try(but their android version not stable yet), or find out how to do that in their code.

2 Comments

Code push is very good tool for dynamicaly loading js and publish updates to it
unfortunately its deprecated :-(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.