Building a Release APK and AAB file for Your React Native Android Project
Prerequisites :
Java Development Kit (JDK): React Native relies on the JDK. Make sure you have it installed and configured in your development environment.
Android Studio (Recommended): While not strictly required, Android Studio is helpful for managing settings, viewing the build process output, and potentially troubleshooting. Especially useful in case you want to change icons , rounded icons which are required are best managed from android studio .
Step By Step Guide :
Here's a systematic breakdown of generating a signed release APK for your React Native Android project, incorporating the best aspects of clarity and organization:
Generate an Upload Key
Open a terminal window as administrator. Navigate to the JDK's "bin" directory (usually located at
C:\Program Files\Java\jdkx.x.x_x\bin
).
or
Open VS code as administrator. Navigate to your project folder in vscode and than navigate to android by doingcd android
.Execute the keytool command:
Bash, powershell ( any other of your choice)
keytool -genkeypair -v -storetype PKCS12 -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
You can rename your keystore and alias - my-upload-key.keystore (app-renamed-key.keystore), my-key-alias(app-renamed-alias) .
Securely store your keystore: It's critical to keep this file safe and backed up. Losing it means you won't be able to issue updates to your app on the Google Play Store.
Set up Gradle Variables:
Place the
my-upload-key.keystore
file under theandroid/app
directory in your project folder.Create or edit the
gradle.properties
file: You'll either find it in~/.gradle/
gradle.properties
(user-level) or in your project'sandroid/
gradle.properties
(project-level).Add the following lines (replace values with your actual details):
MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore MYAPP_UPLOAD_KEY_ALIAS=my-key-alias MYAPP_UPLOAD_STORE_PASSWORD=***** MYAPP_UPLOAD_KEY_PASSWORD=*****
In password you need to enter the password you entered at the time you generate the keystore key.
Add Signing Config to
build.gradle
Open:
android/app/build.gradle
Add within the
android
section:Gradle
android { ... 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 } } }
Before you proceed further and Generate the build file or release apk. You might want to change your app name or app icons or app version , for that refer to this article : Guide to how to change app name , icon and version of your apk with best solution.
Generate the Release APK
Open a terminal in your project's root directory
Execute the build command:
In Bash or any terminal of your choice.
For MacOS & Linux :
cd android && ./gradlew assembleRelease
For Windows :
cd android; ./gradlew assembleRelease
Find your APK: The signed APK will be in
android/app/build/outputs/apk/release/app-release.apk
To generate release AAB file for windows:
cd android; ./gradlew bundleRelease
6. To clean the build directory :
cd android; ./gradlew clean
Important Notes
Protect your keystore: Treat it like a highly sensitive asset. Loss or compromise means losing the ability to update your app.
The
assembleRelease
task: This Gradle task cleans your project, builds it in release mode, and signs it with your configuration.
Subscribe to my newsletter
Read articles from Vishesh Gupta directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by