打开终端生成签名文件
keytool -genkey -v -keystore ~/sign.jks -keyalg RSA -keysize 2048 -validity 10000 -alias sign
输入密钥库口令:
再次输入新口令:
您的名字与姓氏是什么?
[Unknown]: yuanzhiying
您的组织单位名称是什么?
[Unknown]: gongsi
您的组织名称是什么?
[Unknown]: gongsi
您所在的城市或区域名称是什么?
[Unknown]: beijing
您所在的省/市/自治区名称是什么?
[Unknown]: beijing
该单位的双字母国家/地区代码是什么?
[Unknown]: CN
CN=yuanzhiying, OU=gongsi, O=gongsi, L=beijing, ST=beijing, C=CN是否正确?
[否]: Y
正在为以下对象生成 2,048 位RSA密钥对和自签名证书 (SHA256withRSA) (有效期为 10,000 天):
CN=yuanzhiying, OU=gongsi, O=gongsi, L=beijing, ST=beijing, C=CN
[正在存储/Users/yuanzhiying/sign.jks]
查看生成的签名文件
keytool -list -v -keystore sign.jks
输入密钥库口令: <输入密钥>
在Android Studio中flutter项目目录/android/app下创建文件夹key,将生成的sign.jks文件拖放到key文件夹下。
image.png
Flutter获取SHA1
keytool -list -v -keystore ~/.android/debug.keystore -alias androiddebugkey -storepass android -keypass android
keytool -list -v -keystore /Users/nnianhou/Desktop/flutter_manchuan_kankan/android/app/key/sign.jks
在flutter项目目录android下创建文件key.properties,并添加以下内容:
storePassword=123456
keyPassword=123456
keyAlias=sign
storeFile=key/sign.jks
打开/android/app/build.gradle文件,添加以下内容
def keystorePropertiesFile = rootProject.file("key.properties")
def keystoreProperties = new Properties()
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
image.png
在android {}这一行找到内部以下相似代码
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{
release{
keyAlias keystoreProperties['keyAlias']
keyPassword keystoreProperties['keyPassword']
storeFile keystoreProperties['storeFile'] ? file(keystoreProperties['storeFile']) : null
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.release
}
}
打包
可以打包两种文件:APK和AAB(google最新推荐,但是部分应用商城不支持)
打包APK
在android studio项目下的terminal中,执行打包命令:
flutter build apk
image.png
打包AAB
flutter build appbundle
网友评论