Categories
React-Native

Preparing a release with React-Native for Android

In React-Native, debugging is relatively easy but preparing an app for Google Play Store or apk for your phone needs a key to sign your app.

Get in CMD as administrator. Go to the JDK directory. cd C:\Program Files\Java\jdk*****\bin
Type the following to create a file called my-upload-key.keystore in that folder. You can change the keystore name or alias. It will ask for password, i recommend you to type a strong one.

keytool -genkeypair -v -keystore my-upload-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

Copy that keystore file to android/app folder in your application directory.

Edit android/gradle.properties and add the following.

MYAPP_UPLOAD_STORE_FILE=my-upload-key.keystore
MYAPP_UPLOAD_KEY_ALIAS=my-key-alias
MYAPP_UPLOAD_STORE_PASSWORD=YOUR_PASSWORD
MYAPP_UPLOAD_KEY_PASSWORD=YOUR_PASSWORD

Edit android/app/build.gradle, add the release {} part and change signingConfigs.debug as .release

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
        }
    }
}

cd in android folder and type

gradlew bundleRelease

AAB file is now ready in android/app/build/outputs/bundle/release/app.aab . You can submit to Google Play Store.

To test the release and create an apk file. Run app with following.

react-native run-android --variant=release

Your apk is ready in android\app\build\outputs\apk\release