React Native Android package APK

Produce signature keys

You can generate a private key using the keytool command. It can also be executed from a terminal.

keytool -genkeypair -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
Copy the code

This command will ask you to enter the password for the keystore and the corresponding key, and then set up some publishing information. Finally, it generates a keystore file called my-release-key.keystore in the Android /app directory.

After running the above statement, the keystore should have generated a single key with a validity period of 10000 days. The alias after the alias argument is the one you will need to sign your application in the future, so remember to record this alias.

Set the gradle variable

  1. themy-release-key.keystoreFile into your projectandroid/appFolder (default).
  2. The editor~/.gradle/gradle.properties(global configuration, effective for all items) or project directory/android/gradle. The properties (project configuration, applies only to respective project). If there is nogradle.propertiesCreate your own file and add the following code (be careful to replace **** with the password for the corresponding key)
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore MYAPP_RELEASE_KEY_ALIAS=my-key-alias MYAPP_RELEASE_STORE_PASSWORD=*****  MYAPP_RELEASE_KEY_PASSWORD=*****Copy the code

Add the signature configuration to the Gradle configuration for your project

Edit android/app/build.gradle in your project directory and add the following signature configuration:

. android { ... defaultConfig { ... } 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 // Release package instead of debug}}}...Copy the code

Generate APKS for different CPU architectures to reduce the size of APK files

  1. Can be found inandroid/app/build.gradleChange the following code (false to true) to generate multiple APKs for different CPU architectures.
// def enableSeparateBuildPerCPUArchitecture = false
def enableSeparateBuildPerCPUArchitecture = true
Copy the code
// universalApk false
universalApk true  // Generate an additional generic APK for different CPU architectures
Copy the code
  1. android/gradle.propertiesOpen comment 13 to adjust memory Settings so that memory does not run out.
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
Copy the code

Generate and publish APK packages

The terminal runs the following command

cd android // Go to the Android directory
./gradlew assembleRelease
Copy the code

AssembleRelease (assembleRelease); gradlew (assembleRelease); gradlew In the traditional CMD command line of Windows, the./ is removed.

Generate the APK is located in the android/app/build/outputs/APK/release/app – the APK, it can be used to publish already.

The original official