Android 签名应用在密钥库或属性不存在时回退



我的应用程序signingConfigs,我将密钥库文件和keystore.properties存储在app/.signing上,这是gitignore 的。因此,当我的队友克隆存储库时,会发生错误,因为keystore.properties不存在。
这是我的应用级别分级设置。

File keystorePropertyFile = project.file('.signing/keystore.properties')
boolean useSigning = keystorePropertyFile.exists()
...
android {
...
signingConfigs {
release {
if (useSigning) {
Properties properties = new Properties()
properties.load(keystorePropertyFile.newDataInputStream())
keyAlias properties['keyAlias']
keyPassword properties['keyPassword']
storeFile file(properties['storeFile'])
storePassword properties['storePassword']
}
}
}
buildTypes {
debug {
signingConfig signingConfigs.release
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.release
}
}
...
}

Gradle 同步是可以的,但是在构建 APK 时出现错误,指出未为签名配置版本设置密钥库文件

当密钥库或属性文件不存在时,我想使用 android 默认调试密钥对应用程序进行签名。

这是我的解决方法。一切都与时髦有关。

Properties properties = new Properties()
File propertyFile = project.file('.signing/keystore.properties')
def keyAliasProp, keyPasswordProp, storeFileProp, storePasswordProp
def hasKeyInfo = propertyFile.exists()
if (hasKeyInfo) {
properties.load(propertyFile.newDataInputStream())
def keystoreFile = file(properties['storeFile'])
hasKeyInfo = keystoreFile.exists()
if (hasKeyInfo) {
keyAliasProp = properties['keyAlias']
keyPasswordProp = properties['keyPassword']
storeFileProp = keystoreFile
storePasswordProp = properties['storePassword']
}
}
...
android {
...
signingConfigs {
if (hasKeyInfo) { // key part
release {
keyAlias keyAliasProp
keyPassword keyPasswordProp
storeFile storeFileProp
storePassword storePasswordProp
}
}
}
buildTypes {
debug {
if (hasKeyInfo) { // key part
signingConfig signingConfigs.release
}
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
if (hasKeyInfo) { // key part
signingConfig signingConfigs.release
}
}
}
...
}

最新更新