设置 debug和release 使用默认签名
项目上右键 Open Module Settings.
最后会在gradle 中生成配置
改良写法:
把签名信息(主要是密码)写在gradle中是不安全的,我们可以把这些签名信息添加到gradle.properties:
RELEASE_KEY_PASSWORD = 123456
RELEASE_KEY_ALIAS = releaseKey
RELEASE_STORE_PASSWORD = 123456
RELEASE_STORE_FILE = key/releaseKey.jks
然后在build.gradle中引用即可:
android {
signingConfigs {
config_release {
storeFile file(RELEASE_STORE_FILE)
keyAlias RELEASE_KEY_ALIAS
storePassword RELEASE_KEY_PASSWORD
keyPassword RELEASE_STORE_PASSWORD
}
}
}
更安全写法:
把它改成每次打包时手动输入密码才是最安全的:
android {
signingConfigs {
config_release {
storeFile file(RELEASE_STORE_FILE)
keyAlias RELEASE_KEY_ALIAS
storePassword System.console().readLine("\\\\nKeystore password:")
keyPassword System.console().readLine("\\\\nKey password:")
}
}
}