第一步:生成key
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
第二步:在android/app下創(chuàng)建key目錄,把生成的my-release-key.keystore放進去
第三步:在android創(chuàng)建key.properties文件寫入如下代碼
storePassword=123456 ## 這里是之前設(shè)置的密碼
keyPassword=123456 ## 這里是之前設(shè)置的密碼
keyAlias=my-key-alias
storeFile=key/my-release-key.keystore
第四步:找到android/app下的build.gradle修改如下內(nèi)容
在 android { 上面加上下面這段
def keystorePropertiesFile=rootProject.file('key.properties')
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
然后把
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
}
}
修改為
signingConfigs {
release {
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile file(keystoreProperties['storeFile'])
storePassword keystoreProperties['storePassword']
}
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
一切就緒:運行 flutter build apk 進行打包
我因為引入了 amap_base_map 導(dǎo)致閃退,所以打包時運行這段指令
flutter build apk --target-platform android-arm64