电脑上需要安装JDK,并配置好JDK运行环境,并可以正常运行 keytool 命令
keytool
密钥和证书管理工具
命令:
-certreq 生成证书请求
-changealias 更改条目的别名
-delete 删除条目
-exportcert 导出证书
-genkeypair 生成密钥对
-genseckey 生成密钥
-gencert 根据证书请求生成证书
-importcert 导入证书或证书链
-importpass 导入口令
-importkeystore 从其他密钥库导入一个或所有条目
-keypasswd 更改条目的密钥口令
-list 列出密钥库中的条目
-printcert 打印证书内容
-printcertreq 打印证书请求的内容
-printcrl 打印 CRL 文件的内容
-storepasswd 更改密钥库的存储口令
使用 "keytool -command_name -help" 获取 command_name 的用法
windows 下运行:
keytool -genkey -v -keystore c:/flutter/key.jks
-storetype JKS -keyalg RSA -keysize 2048 -validity 10000 -alias key
Linux OR MAC 下运行:
keytool -genkey -v -keystore ~/key.jks -keyalg RSA
-keysize 2048 -validity 10000 -alias key
在项目目录的下的android/下面创建 key.properties,其内容如下:
storePassword=<password from previous step>
keyPassword=<password from previous step>
keyAlias=key
storeFile= c:/flutter/key.jks
#<location of the key store file, such as /Users/<user name>/key.jks>
编辑项目文件下的 android/app/build.gradle,在 android { 上面加上如下内容:
def keystoreProperties = new Properties()
def keystorePropertiesFile = rootProject.file('key.properties')
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(new FileInputStream(keystorePropertiesFile))
}
android {
compileSdkVersion 28
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
。。。。。。。
将
buildTypes {
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now,
// so `flutter run --release&#