1. 生成一個簽名密鑰
可以用keytool
命令生成一個私有密鑰。在Windows上keytool
命令放在JDK的bin目錄中(比如C:\Program Files\Java\jdkx.x.x_x\bin
),你可能需要在命令行中先進入那個目錄才能執(zhí)行此命令暴凑。
$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
2. 創(chuàng)建key.properties文件(your_project/android/key.properties
)
#創(chuàng)建KEY時輸入的密鑰庫密碼
storePassword=666666
#創(chuàng)建KEY時輸入的密鑰密碼
keyPassword=666666
#密鑰名稱[默認是key兴猩,這里我設置為my-key-alias]
keyAlias=my-key-alias
#簽名的存放路徑【我把生成的my-release-key.keystore文件扔到了d盤】
storeFile=D:/my-release-key.keystore
3. 修改your_project/android/app/build.gradle
...
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
android {
...
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
// signingConfig signingConfigs.debug
signingConfig signingConfigs.release
}
}
}
4. 生成apk
$ flutter build apk
生成的
app-release.apk
在項目的your_project/build/output/apk/release
目錄下
5. 安裝
$ adb install app-release.apk