强制使用相同的证书来签署不同的“buildTypes";是为特定的“产品风味"配置的? [英] Force to use same certificate to sign different "buildTypes" that are configured for a particular "productFlavor"?

查看:41
本文介绍了强制使用相同的证书来签署不同的“buildTypes";是为特定的“产品风味"配置的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:

我正在使用构建变体生成构建.以下是配置:

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:

  1. developReleasedevelopDebug 应该只使用 signingConfigs.develop 签名代码>

productionReleaseproductionDebug 应仅使用 signingConfigs.production

另一个与此类似的问题导致我执行上述操作:SHA-1 与 buildTypes(调试和发布)不同相同的 productFlavors Firebase?

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

并在 buildTypes 中添加新属性,如

And add new property within the buildTypes like

  • 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.

这篇关于强制使用相同的证书来签署不同的“buildTypes";是为特定的“产品风味"配置的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆