How to Generate React-Native APK - Solution For APK Installation ERROR
You can simply able to solve your generated APK installation error in test devices or Android Emulator. The following worked for me: Lets see how to do it,
NOTE: you can simply drag and drop the Android apk to the emulator and it will automatically starts installing.
Generate a upload key
Place the my-upload-key.keystore file under the android/app directory in your project folder. Then edit the file android/gradle.properties and add the following (replace **** with the correct keystore password, alias and key password)
Adding signing config to your app's Gradle config
In your app/build.gradle
Generating the release
Run the following in a terminal from root folder of your React Native Project
NOTE: If ./gradlew assembleRelease is showing not your internal command. Just remove "./" and run gradlew assembleRelease only.
Which Build command line should I Use
assembleDebug
- This builds an apk for your project using the debug variant.
- This creates an APK named module_name-debug.apk in project_name/module_name/build/outputs/apk/. The file is already signed with the debug key and aligned with zipalign, so you can immediately install it on a device.
installDebug
- This builds an apk for your project using the debug variant and then installs it on a connected device
- Or to build the APK and immediately install it on a running emulator or connected device, instead invoke installDebug.
assembleRelease
- This creates a release apk of your app. You would then need to sign it using the command line or by setting the signing details in your build.gradle (see above instructions) and then you can install it on your device using adb.
bundleRelease
- This creates a release aab, this is Google's preferred format for uploading to the Play Store.
- Android App Bundles include all your app’s compiled code and resources, but defer APK generation and signing to Google Play. Unlike an APK, you can't deploy an app bundle directly to a device. So, if you want to quickly test or share an APK with someone else, you should instead build an APK.
installRelease
- You will have to set up the signing above for this to work for a release build. It is the same as the installDebug but it creates a signed release variant and installs it on a connected device.
Usage
- I use assembleRelease to build an apk that I want to share with other people.
- I use installRelease when I want to test a release build on a connected device.
- I use bundleRelease when I am uploading my app to the Play Store.
NOTES: --variant release is only available if you've set up signing as described above.
You can create an APK for each CPU by changing the following line in android/app/build.gradle:
Which is helpfull to upload your app without error on other App stores like Amazon AppStore and APKFiles.
See this final example APK HERE.
Thanks for reading this and leave your comments.