Android Studio gradle 签名设置
如何使用自定义签名文件?
在项目的build.gradle中 设置示例
android {
...
signingConfigs{
debug{
storeFile file("../config/debug.keystore")
}
release {
storeFile file("MyKeyStore.jks")
}
}
....
buildTypes {
release {
minifyEnabled false
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
File propFile = file('../config/signing.properties');
if (propFile.exists()) {
def Properties props = new Properties()
props.load(new FileInputStream(propFile))
if (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 {
android.buildTypes.release.signingConfig = null
}
} else {
android.buildTypes.release.signingConfig = null
}
}
signing.properties 文件内容
STORE_FILE=../config/MyKeyStore.jks
STORE_PASSWORD=123456
KEY_ALIAS=mykey
KEY_PASSWORD=123456
如此 可以在release的时候 使用自定义的签名文件
另一种方法 不使用property方式示例
android {
'''
signingConfigs {
debug {
storeFile file('../config/debug.keystore')
storePassword '23456'
keyAlias 'mykey'
keyPassword '123456'
}
release {
storeFile file('../config/debug.keystore')
storePassword '23456'
keyAlias 'mykey'
keyPassword '123456'
}
}
buildTypes {
release {
signingConfig signingConfigs.release
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
signingConfig signingConfigs.debug
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
总结
以上两种方式 按需使用
BR