生成签名密钥:
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
设置gradle变量:
a. 把my-release-key.keystore文件放到你工程中的android/app文件夹下
b. 编辑~/.gradle/gradle.properties:MYAPP_RELEASE_STORE_FILE=my-release-key.keystoreMYAPP_RELEASE_KEY_ALIAS=my-key-aliasMYAPP_RELEASE_STORE_PASSWORD=***** // 替换成相应的密码MYAPP_RELEASE_KEY_PASSWORD=***** // 替换成相应的密码
修改配置文件(android/app/build.gradle):
a. 添加签名:...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 }}}...// 找到 def enableSeparateBuildPerCPUArchitecture = false// 修改为 def enableSeparateBuildPerCPUArchitecture = true// 找到 universalApk false// 修改为 universalApk true// 找到 def enableProguardInReleaseBuilds = false// 修改为 def enableProguardInReleaseBuilds = true// 最后清空缓存// Android Studio Build > Clean Project
生成APK包:
cd android && ./gradlew assembleRelease// 包位置 android/app/build/outputs/apk/app-release.apk
安装包并在设备上测试:
cd android && ./gradlew installRelease