背景:
我正在使用构建变体生成构建。以下是配置:
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
。
预期输出
当我生成签名的apk时,我希望gradle为我做以下事情:
developRelease
且 developDebug
只能使用signingConfigs.develop
productionRelease
且 productionDebug
只能使用signingConfigs.production
与此类似的另一个问题让我做了以上事情:SHA-1 different for buildTypes (debug and release) for same productFlavors Firebase?
答案 0 :(得分:3)
删除
代码块中其他地方的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
自动签署您的应用程序。默认情况下,调试版本变体使用调试密钥进行签名,以便在开发设备上进行安装。声明其他签名配置以便发布到Google Play商店。
<强>更新强> 正如另一个答案指出的那样,
在自定义buildTypes下添加debuggable true属性 想要调试构建并查看日志。
答案 1 :(得分:0)
感谢@Mani在buildTypes.debug
上发光。
根据documentation Application Signing
自动签署您的应用程序。默认情况下,调试版本变体使用调试密钥进行签名,以便在开发设备上进行安装。声明其他签名配置以便发布到Google Play商店。
以上是非常正确的。 无需从signingConfig
移除productFlavors
。另外,在自定义debuggable true
下添加buildTypes
属性,您要根据该属性调试构建并查看日志。
您可以根据需要在buildTypes
添加以下属性:
{name=withDevelopDebug, debuggable=false, testCoverageEnabled=false,
jniDebuggable=false, pseudoLocalesEnabled=false,
renderscriptDebuggable=false, renderscriptOptimLevel=3,
minifyEnabled=false, zipAlignEnabled=true, signingConfig=null,
embedMicroApp=true, buildConfigFields={}, resValues={},
proguardFiles= [], consumerProguardFiles=[], manifestPlaceholders={}}
因为,我在debuggable true
和withProductionDebug
withDevelopDebug
signingConfigs {
production {
storeFile file("some_path/buildsystem/keystore/some.release.keystore.jks")
storePassword "somepassword"
keyAlias "somekeyalias"
keyPassword "some"
}
develop {
storeFile file(".some_path./buildsystem/keystore/someother.debug.keystore.jks")
storePassword "someother"
keyAlias "someotherkeyalias"
keyPassword "someother"
}
}
buildTypes {
withProductionRelease{
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
withProductionDebug{
minifyEnabled false
debuggable true
}
withDevelopRelease{
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
withDevelopDebug{
minifyEnabled false
debuggable true
}
}
productFlavors {
production {
signingConfig signingConfigs.production
}
develop {
applicationIdSuffix ".develop"
signingConfig signingConfigs.develop
}
}