Let's be honest, even if you really like React Native, you were frustrated with it at least once. Especially if you have just started working with it.
So I hope this post will help at least some of you :D.
This are 7 steps how to generate your Android APK file so you can test your app on a real phone and share it with your friends or testers.
Currently tested and working with latest version today 0.64
Generate private signing key using keytool. How to do that you can find it here. If you are using OpenJDK, then your keytool is probably in C:\Program Files\OpenJDK\openjdk-xxxxx-xxx\bin.
Make sure to copy signing key to /android/app/ folder of your react native app.
-
Edit gradle.properties file in your android folder by adding following (make sure to replace ***** with a password that you want to use, my-upload-key and my-key-alias with the names you want):
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore<br> MYAPP_UPLOAD_KEY_ALIAS=my-key-alias<br> MYAPP_UPLOAD_STORE_PASSWORD=*****<br> MYAPP_UPLOAD_KEY_PASSWORD=*****<br>
-
Add signing config in Gradle config file. Edit the build.gradle file in your android/app/ folder:
... android { ... defaultConfig { ... } signingConfigs { release { if (project.hasProperty('MYAPP_UPLOAD_STORE_FILE')) { storeFile file(MYAPP_UPLOAD_STORE_FILE) storePassword MYAPP_UPLOAD_STORE_PASSWORD keyAlias MYAPP_UPLOAD_KEY_ALIAS keyPassword MYAPP_UPLOAD_KEY_PASSWORD } } } buildTypes { release { ... signingConfig signingConfigs.release } } } ...
Check if the file my-release-key.keystore ("my-release-key" is the key you entered earlier) is located in path /android/app/ (if it is not there, make sure to copy it there from the folder where your key was created).
Create assets folder in /android/app/src/main/
-
Open your terminal and position yourself to root folder. Run command:
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
Open one more terminal and position yourself into android folder. Run command:
gradlew clean
or
./gradlew clean
After previous command is finished run:
gradlew assembleRelease -x bundleReleaseJsAndAssets
or
./gradlew assembleRelease -x bundleReleaseJsAndAssets
If everything goes well, you can find your signed apk file in
android/app/build/outputs/apk/
or
android/app/build/outputs/apk/release/
Top comments (3)
Thanks this helped me a lot
In step 2, you should mention user must save the generated my-upload-key.keystore file in specific path first.
I did some updates. Thank you for your comment.