我在同一个 Android Studio 项目中有两个不同的应用程序。我有两种 flavor 'flavor1' 和 'flavor2' 具有三种不同的构建类型 'staging'、'debug' 和 'release'
问题是我需要为每个应用程序使用不同的 keystore 。
现在我有了这个,但它只用同一个 keystore 签名。
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.getProperty('STORE_FILE'))
android.signingConfigs.release.storePassword = props.getProperty('STORE_PASSWORD')
android.signingConfigs.release.keyAlias = props.getProperty('KEY_ALIAS')
android.signingConfigs.release.keyPassword = props.getProperty('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
}
}
}
buildTypes {
staging {
debuggable true
signingConfig android.signingConfigs.debug
}
debug {
debuggable true
signingConfig android.signingConfigs.debug
}
release {
debuggable false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.release
minifyEnabled false
}
}
最佳答案
您可以创建特定于 flavor 的签名配置:
一个例子:
signingConfigs {
flavor1Release {
storeFile file('home/keys/flavor1keystore.keystore')
storePassword 'keystorePassword'
keyAlias 'alias'
keyPassword 'aliasPassword'
}
flavor2Release {
storeFile file('home/keys/flavor2keystore.keystore')
storePassword 'keystorePassword2'
keyAlias 'alias2'
keyPassword 'aliasPassword2'
}
}
然后按照您的喜好,选择正确的签名配置:
productFlavors {
def flavor1SigningVariable = signingConfigs.flavor1Release
def flavor2SigningVariable = signingConfigs.flavor2Release
flavor1 {
signingConfig flavor1SigningVariable
}
flavor2 {
signingConfig flavor2SigningVariable
}
}
关于android - 每个风格和构建类型的signingConfig 必须不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31295437/