简体   繁体   中英

How to create and use React Native with Android using an offline bundle

I'm new with React Native, and I want to create a deployable version of the app for iOS and Android.

I saw in the oficial web page how to use an offline bundle for iOS, and it works fine. I generated the offline bundle with the following command without any problem: react-native bundle --dev false --entry-file index.ios.js --bundle-output ios/main.jsbundle --platform ios

And I did the following change, and it worked fine on iOS. http://facebook.github.io/react-native/docs/running-on-device-ios.html#using-offline-bundle

However, I'm not able to do the same for Android, and I can't find any example of it on the internet. I executed the following command and the offline bundle was generated correctly. react-native bundle --dev false --entry-file index.android.js --bundle-output android/main.jsbundle --platform android However, I don't know how to indicate to the app the location of this generated bundle.

thoughts?

Debug mode: Connect your device to computer and in your code directory, simply run 'react-native run-android'. Once the app launches you see a red screen, Shake the device or use frappe to simulate shake gesture for the device, click on dev settings from the menu, then click 'Debug server host and port for device' and enter your computer's ip:8081 (eg 192.168.1.1:8081) and press OK. After this shake the device again (or use frappe) and click reload JS. This will copy the js bundle from your computer to the app and the app will run offline after this.

Release: Signing the apk and generating release apk using commands assembleRelease/installRelease commands handle this already and pack all the JS bundlse required. (see link )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM