RN in Android package release app

Source: Internet
Author: User

Reference: HTTP://WWW.JIANSHU.COM/P/B8811669BCB6

RN in Android package release app

1-: Generate a signature key
You can use the Keytool command to generate a private key. The Keytool command on Windows is placed in the bin directory of the JDK (for example, C:\Program files\java\jdkx.x.x_x\bin), and you may need to enter that directory on the command line to execute this command. On your Mac, enter the command directly into the project root directory:

$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000

This command will ask you to enter the password for the KeyStore (KeyStore) and the corresponding key, and then set up some distribution-related information. Finally, it generates a KeyStore file called My-release-key.keystore.

After running the above statement, a separate key should have been generated in the KeyStore, valid for 10,000 days. The alias after the--alias parameter is what you need to use to sign the app in the future, so remember to record the alias.

Note: Remember to keep your keystore file properly and not upload it to the repository or anywhere else.

2-: Set gradle variable
Put the my-release-key.keystore file under the Android/app folder in your project.
Edit ~/.gradle/gradle.properties(without this file you create one), add the following code (note that the * * is replaced with the corresponding password)
Note: ~ Represents a user directory, such as a C:\Users\ user name on Windows, and a/users/user name on a Mac.

Myapp_release_store_file=my-release-key.keystore
Myapp_release_key_alias=my-key-alias
myapp_release_store_password=*
myapp_release_key_password=*
The above will act as a global gradle variable.

Considerations for KeyStore:
Once you have published your app in the app market (app Bao, 360, etc.), if you want to change your signature, you must republish your app with a different package name (which will also lose all the downloads and ratings). So be sure to back up your keystore and password.

3-: Add a Gradle configuration file that is signed to the project
To edit the android/app/build.gradlein your project directory, add the following signature configuration:

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

4-: Build release APK Package
Just run the following command in the terminal:

$ cd android && ./gradlew assembleRelease

cd Android means to enter the Android directory (if you are already in the Android directory then you do not have to enter).
./gradlew Assemblerelease represents the execution of a script file named Gradlew under the current directory in a PowerShell, Linux, or windows® Windows environment. and its operating parameters are assemblerelease, note this./cannot be omitted, while in Windows the traditional cmd command line needs to be removed.

Gradle's assemblerelease parameter will pack all the JavaScript code used, and then build it into the APK package. If you want to adjust this behavior (such as JS code and static resource packaging default file name or directory structure, etc.), you can look at the Android/app/build.gradle file.

The generated APK file is located in android/app/build/outputs/apk/app-release.apk, which is already available for publishing.

5-: Test the release version of the app

$ cd android && ./gradlew installRelease

Note The Installrelease parameter can only be used after you have completed the signature configuration above. You can now turn off the running packager, because all of your code and framework dependencies are already packaged in the APK package and can be run offline.

Switching between debug and release versions may cause an error signature mismatch when installing back and forth, and you will need to uninstall the previous version before attempting to install it.

6-: Enable Proguard code obfuscation to reduce the size of the APK file (optional)
Proguard is a Java bytecode obfuscation compression tool that removes unused portions of react Native Java (and its dependent libraries), and ultimately effectively reduces the size of the APK.

Important: After you enable Proguard, you must test your app thoroughly again. Proguard Sometimes you need to do some extra configuration for each native library that you introduce. See App/proguard-rules.pro file.

To enable Proguard, set the minifyenabled option to true:

 /*** 在release发行版中启用Proguard来减小 to shrink the Java    bytecode in release builds.*/def enableProguardInReleaseBuilds = true

Personal advice: If your project cannot be run because you added this property, delete this configuration. Because, this really can lead to all sorts of strange problems.

RN Packaging and publishing app in Android

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.