按照官方的5步曲:android
1.在終端裏面,cd 到項目的根目錄後.執行下面這行命令:app
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
而後終端就會讓你輸入口令等信息.如gradle
2.執行第一步會在根目錄下會生成一個XXXXXX.keystore的文件,直接拿到android/app下.ui
3.在android/gradle.properties中加入:spa
MYAPP_RELEASE_STORE_FILE=my-release-key.keystore3d
MYAPP_RELEASE_KEY_ALIAS=my-key-aliascode
MYAPP_RELEASE_STORE_PASSWORD=blog
MYAPP_RELEASE_KEY_PASSWORD=
換爲你剛纔輸入的口令.圖片
4.在android/app/build.gradle添加下面的紅色字.
def enableProguardInReleaseBuilds = trueit
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 }} splits {
....
} buildTypes { release { signingConfig signingConfigs.release ... } }
.....
} } }
}
5.終端cd 到android目錄下.執行命令
./gradlew assembleRelease
等一下終端執行後顯示BUILD SUCCESSFUL.
成功打好了.在項目的android/app/outputs/apk下可見剛纔打好的apk包