Member-only story
In this article, I will show you how to generate the Android signed release APK file in ReactNative.
First, open the terminal and navigate to your project folder. Within the project folder, run the following command to generate the keystore file.
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Then copy the my-release-key.keystore file from the project root folder into the android/app folder.
Then add the following variables into the android/gradle.properties file replacing the passwords with your keystore passwords.
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=password
MYAPP_RELEASE_KEY_PASSWORD=password
Then add the following configuration into the android section of android/app/build.gradle file
signingConfigs {
debug {
storeFile file('debug.keystore')
storePassword 'android'
keyAlias 'androiddebugkey'
keyPassword 'android'
}
release {
if (project.hasProperty('MYAPP_RELEASE_STORE_FILE')) {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.debug
}
release {
// Caution! In production, you need to generate your own keystore file.
// see https://reactnative.dev/docs/signed-apk-android.
signingConfig signingConfigs.debug
minifyEnabled enableProguardInReleaseBuilds
proguardFiles getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro"
signingConfig signingConfigs.release
}
}
Also, add the following snippet into the same section, android.
lintOptions {
checkReleaseBuilds false
abortOnError false
}
Then run the following command
cd android && ./gradlew assembleRelease
After the command has been executed, you should see the release apk file inside the android/app/build/outputs/apk/release folder.
If you get the error, try to delete everything within the android/app/build/outputs/apk/release folder running “./gradlew clean”.
Then again run ./gradlew assembleRelease.