强制使用相同的证书对不同的"buildType"进行签名.为特定的"productFlavor"配置的产品? [英] Force to use same certificate to sign different "buildTypes" that are configured for a particular "productFlavor"?
问题描述
背景:
我正在使用构建变体生成构建.以下是配置:
I am generating builds using build variant. Below are the configurations:
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'
}
}
问题
例如,现在,如果我谈论风味production
,则 productionRelease
使用signingConfigs.production
来签名apk.但是, productionDebug
不使用signingConfigs.production
.
As, of now for example if I talk about flavour production
then productionRelease
uses signingConfigs.production
to sign the apk. But, productionDebug
doesn't uses signingConfigs.production
.
预期输出
当我生成签名的apk时,我希望gradle为我做以下事情:
When I generate the signed apk I want the gradle to do the following for me:
-
developRelease
和developDebug
应该仅使用signingConfigs.develop
productionRelease
和 productionDebug
应该仅使用signingConfigs.production
另一个与此类似的问题导致我执行上述操作: SHA-1对于buildTypes(调试和发布)有所不同相同的产品
Another question that is similar to this which led me to do the above: SHA-1 different for buildTypes (debug and release) for same productFlavors Firebase?
推荐答案
删除
signingConfig signingCongigs.develop
代码块中的其他地方
Remove the
signingConfig signingCongigs.develop
elsewhere in the code block
并在
- withProduction
- withDevelop
现在向其中添加signingConfig
因此,更新的gradle文件如下所示
Thereby your updated gradle file look like as below
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
In the terminal use the below gradle commmand:
gradle assembleProduction
to generate build with production certificates
similarly gradle assembleDevelop
or you can also use gradle assemble
您不能强制gradle选择debug
属性的证书,而可以创建自己的buildTypes
You cannot force gradle to choose the certificates for debug
property rather you could create own buildTypes
根据文档
自动签署您的应用程序.默认情况下,调试构建变体使用调试密钥签名,以便在开发设备上安装.声明其他签名配置,以发布到Google Play商店.
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.
更新: 正如另一个答案所指出的,
Update: As the other answer pointed out,
在您要针对其定制的buildTypes下添加可调试的true属性 要调试构建并查看日志.
Add debuggable true property under custom buildTypes against which you want to debug build and see the logs.
这篇关于强制使用相同的证书对不同的"buildType"进行签名.为特定的"productFlavor"配置的产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!