React native build basic page 6 — package and publish

Time:2020-5-21

Sign the package to release the APK installation package

  • Please refer to the following two articles:
  • Android package APK method of ReactNative
  • Real native publishes the signature package of APP apk

How to publish an apk

  1. First, make sure that you have configured all RN environments correctly
  2. On the CMD command line, run this sentencekeytool -genkey -v -keystore my-release-key2.keystore -alias my-key-alias2 -keyalg RSA -keysize 2048 -validity 10000
  • Among them:my-release-key.keystoreIndicates the name of the signature file you want to generate later [it’s important to find a small book to write down]
  • -aliasThe latter part is also very important. You need to find a small book to write down. The name can be changed according to your own needsmy-key-alias
  • When running to find a command, you need to enter a series of parameters, find a password, [be sure to find a small notebook to write down]
  1. After the signature is generated, the signature is saved to the user directory by defaultC:\Users\liulongbin\my-release-key2.keystore
  2. Copy your signing certificate to the Android / APP directory.
  3. editandroid -> gradle.propertiesFile, at the end, add the following code:
MYAPP_RELEASE_STORE_FILE=your keystore filename
MYAPP_RELEASE_KEY_ALIAS=your keystore alias
MYAPP_RELEASE_STORE_PASSWORD=*****
MYAPP_RELEASE_KEY_PASSWORD=*****
  1. Edit Android / APP/ build.gradle Add the following code to the file:
...
android {
    ...
    defaultConfig { ... }
    + signingConfigs {
    +    release {
    +        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
        }
    }
}
...
  1. Enter theandroidFolder, open the terminal in the current directory, and then enter./gradlew assembleReleaseStart to release the release version of APK;
  2. When the release is completed, enter theandroid\app\build\outputs\apkDirectory, foundapp-release.apk, this is the complete installation package after we have released it; it can be uploaded to major app stores for users to use;

Note: please remember to keep your keystore file properly, and do not upload it to the version library or other places.