第一步:生成key
keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
第二步:在android/app下创建key目录,把生成的my-release-key.keystore放进去
第三步:在android创建key.properties文件写入如下代码
storePassword=123456 ## 这里是之前设置的密码
keyPassword=123456 ## 这里是之前设置的密码
keyAlias=my-key-alias
storeFile=key/my-release-key.keystore
第四步:找到android/app下的build.gradle修改如下内容
在 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 导致闪退,所以打包时运行这段指令
flutter build apk --target-platform android-arm64