React native package release steps

1. Generate a signing key

keytool -genkey -v -keystore my-release-key.keystore -alise

my-key-alias -keyalg RSA -keysize 2048 -validity 10000

keytool -genkey -v -keystore my-release-key.keystore -alias

my-key-alias -keyalg RSA -keysize 2048 -validity 10000

 

2. Find the path /android/app/src/main, and create a new assets folder in this directory

 

3. Download and save index.android.bundle to the assets resource folder in the project directory

curl -k "http://localhost:8081/index.android.bundle" > android/app/src/main/

assets/index.android.bundle

This command is the key point. If the file does not exist in the assets directory, the package to apk will display blank when executed.

Or generate a bundle file with the following command

react-native bundle --platform android --entry-file index.android.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest  android/app/src/main/res/ --dev false

 

 

4, Add the android keystore configuration of gradle

in build.gradle file

//sign

signingConfigs{

  release{

    storeFile file("/my-release-key.keystore")

    storePassword "password"

    keyAlias ​​"name of keyAlias"

    keyPassword "password"

  }

}

buildTypes{

  release{

    minifyEnable false

    proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'

    signingConfig signingConfigs.release //Add this sentence to reference the signing configuration

  }

}

 

5. Enable Proguard code obfuscation to reduce apk file size

Proguard is a java bytecode obfuscation compression tool that removes React Native java (and its dependencies)

The parts that are not used will eventually effectively reduce the size of the apk.

Important: After enabling Proguard, the application must be fully tested. Proguard sometimes requires some additional configuration for each native library you import.

See app/proguard-rules.pro file.

def enableProguardInReleaseBuilds = true

 

6. Execute the gradle assembleRelease command in the /android/ directory, the packaged files are in the /android/app/build/outputs/apk directory,

For example, app-release.apk. If you encounter problems with packaging, you can perform gradle clean first.

 

Install the gradle tool (the version is the same as android\gradle\wrapper), and configure the environment variables, configure GRADLE_HOME to the gradle root directory,

Then add %GRADLE_HOME%/bin ($GRADLE_HOME/bin for linux or mac) to the PATH environment variable.

After configuration, run gradle -v to check if the installation is correct.

 

7. Publish the apk to major application markets.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693463&siteId=291194637