你可以把.jks
随处归档。
这意味着您可以将文件放在项目中,也可以将文件放在外部文件夹中(只需查看下面的路径)。
这取决于您的政策。
只需使用 gradle 来配置 apk 的签名即可。
android {
signingConfigs {
release
}
buildTypes {
release {
signingConfig signingConfigs.release
}
}
}
简单的方法:只需在 build.gradle 文件中定义凭据即可。
signingConfigs {
release {
//Pay attention to the path. You can use a relative path or an absolute path
storeFile file("../your_key_store_file.jks")
storePassword 'some_password'
keyAlias 'alias_name'
keyPassword 'key_password'
}
}
使用 .properties 文件将凭据存储在脚本之外(例如,如果您不想将凭据推送到 git 存储库中)。
例子:signing.properties
STORE_FILE=/path/to/your.keystore
STORE_PASSWORD=yourkeystorepass
KEY_ALIAS=projectkeyalias
KEY_PASSWORD=keyaliaspassword
然后在 build.gradle 文件中获取这些值:
signingConfigs {
release
}
然后定义:
def Properties props = new Properties()
def propFile = new File('signing.properties')
if (propFile.canRead()){
props.load(new FileInputStream(propFile))
if (props!=null && props.containsKey('STORE_FILE') && props.containsKey('STORE_PASSWORD') &&
props.containsKey('KEY_ALIAS') && props.containsKey('KEY_PASSWORD')) {
android.signingConfigs.release.storeFile = file(props['STORE_FILE'])
android.signingConfigs.release.storePassword = props['STORE_PASSWORD']
android.signingConfigs.release.keyAlias = props['KEY_ALIAS']
android.signingConfigs.release.keyPassword = props['KEY_PASSWORD']
} else {
println 'signing.properties found but some entries are missing'
android.buildTypes.release.signingConfig = null
}
}else {
println 'signing.properties not found'
android.buildTypes.release.signingConfig = null
}