Build and Install unsigned apk on device without the development server?
As I am new in react-native so if there is anything wrong in steps let me know.
I have build a react native android app using the command as per documentation
react-native android
while running on device the following command was used
react-native run-android
which gives me the output of 2 apk files in my projectfolder/android/app/build/outputs/apk
now when I use to install this apk after the installation it ask for an development server to connect to bundle the JS. But my requirement is that the user doesn't have to struggle with the development server just he needs to install the apk and everything is done.
Have gone through some stackoverflow Questions but not helpful to build unsigned apk which doesn't require development server.
Can you guys help me finding the way that how to build and unsigned apk in react native?
Solution 1:
You need to manually create the bundle for a debug build.
Bundle debug build:
#React-Native 0.59
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/src/main/assets/index.android.bundle --assets-dest ./android/app/src/main/res
#React-Native 0.49.0+
react-native bundle --dev false --platform android --entry-file index.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
#React-Native 0-0.49.0
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
Then to build the APK's after bundling:
$ cd android
#Create debug build:
$ ./gradlew assembleDebug
#Create release build:
$ ./gradlew assembleRelease #Generated `apk` will be located at `android/app/build/outputs/apk`
P.S. Another approach might be to modify gradle scripts.
Solution 2:
Please follow those steps.
Bundle your js:
if you have index.android.js in project root then run
react-native bundle --dev false --platform android --entry-file index.android.js --bundle-output ./android/app/build/intermediates/assets/debug/index.android.bundle --assets-dest ./android/app/build/intermediates/res/merged/debug
if you have index.js in project root then run
react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res
Create debug apk:
cd android/
./gradlew assembleDebug
Then You can find your apk here:
cd app/build/outputs/apk/