背景:
我正在使用构建变体生成构建。以下是配置:
signingConfigs {
production {
storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
storePassword "somepassword"
keyAlias "somekeyalias"
keyPassword "some"
v2SigningEnabled false
}
develop {
storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
storePassword "someother"
keyAlias "someotherkeyalias"
keyPassword "someother"
v2SigningEnabled false
}
}
productFlavors {
production {
signingConfig signingConfigs.production
}
develop {
applicationIdSuffix ".develop"
signingConfig signingConfigs.develop
}
}
buildTypes {
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
问题
例如,现在如果我谈论 flavor production
那么 productionRelease
使用 signingConfigs.production
来签署apk。但是,productionDebug
不使用 signingConfigs.production
。
预期输出
当我生成签名的 apk 时,我希望 gradle 为我执行以下操作:
developRelease
和developDebug
应该只用signingConfigs.develop签名
productionRelease
和productionDebug
应该只用signingConfigs.production签名
另一个与此类似的问题导致我执行上述操作:SHA-1 different for buildTypes (debug and release) for same productFlavors Firebase?
最佳答案
删除
signingConfig signingCongigs.develop
在代码块的其他地方
并在 buildTypes 中添加新属性,例如
- 与生产
- 与开发
现在添加signingConfig
因此,您更新后的 gradle 文件如下所示
signingConfigs {
production {
storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
storePassword "somepassword"
keyAlias "somekeyalias"
keyPassword "some"
v2SigningEnabled false
}
develop {
storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
storePassword "someother"
keyAlias "someotherkeyalias"
keyPassword "someother"
v2SigningEnabled false
}
}
productFlavors {
production {
}
develop {
applicationIdSuffix ".develop"
}
}
buildTypes {
/* NOTE: the debug block is not required because it is a default
* buildType configuration; all of its settings are defined implicitly
* by Gradle behind the scenes.
*/
debug {
minifyEnabled false
}
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.production
}
withProduction {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
signingConfig signingConfigs.production
}
withDevelop {
minifyEnabled false
signingConfig signingConfigs.develop
debuggable true
}
}
在终端中使用下面的 gradle 命令:
gradle assembleProduction
生成带有生产证书的构建
类似地 gradle assembleDevelop
或者你也可以使用 gradle assemble
您不能强制 gradle 为 debug
属性选择证书,而是您可以创建自己的 buildTypes
Automate signing your applications. Debug build variants are, by default, signed with a debug key for installation on development devices. Declare additional signing configurations for publication to the Google Play store.
更新: 正如另一个答案指出的那样,
Add debuggable true property under custom buildTypes against which you want to debug build and see the logs.
关于android - 强制使用相同的证书来签署为特定 "buildTypes"配置的不同 "productFlavor"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45166152/