1、进入android/app目录下运行;
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
2、修改文件:android/app/gradle.properties,增加如下代码:
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore
MYAPP_RELEASE_KEY_ALIAS=my-key-alias
MYAPP_RELEASE_STORE_PASSWORD=xxxxxx
MYAPP_RELEASE_KEY_PASSWORD=xxxxxx
3、添加签名到项目里面:android/app/build.gradle
... 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、运行打包命令:
cd android && ./gradlew assembleRelease
官方参考链接:https://reactnative.cn/docs/0.43/signed-apk-android.html