Create APK file in React Native in Release mode

Viewed 162
2 Answers

You must generate a private key by running

$ keytool -genkey -v -keystore servento.keystore -alias servento-alias -keyalg RSA -keysize 2048 -validity 10000

Then you have to set the generated file my-release-key.keystore under android/app in your project. Edit the file ~/.gradle/gradle.properties as following

MYAPP_RELEASE_STORE_FILE=.keystore
MYAPP_RELEASE_KEY_ALIAS=-alias
MYAPP_RELEASE_STORE_PASSWORD=[YOUR PASSWORD]
MYAPP_RELEASE_KEY_PASSWORD=[YOUR PASSWORD]
Now edit android/app/build.gradle as following:

  signingConfigs {
        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 {
        release {
            signingConfig signingConfigs.release
        }
    }

And in your terminal run cd android && ./gradlew app:assembleRelease Your APK will be generated inside this directory android/app/build/outputs/apk/ as app-release.apk

Related