强制使用相同的证书来签署为特定"productFlavor"配置的不同"buildTypes"?

Anu*_*ngh 7 android gradle apk android-gradle-plugin

背景:

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

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'
    }
}
Run Code Online (Sandbox Code Playgroud)

问题

至于现在,例如,如果我谈论味道production然后productionRelease用于signingConfigs.production签署apk.但是,productionDebug不使用signingConfigs.production.

预期产出

当我生成签名的apk时,我希望gradle为我做以下事情:

  1. developRelease并且developDebug应该只签名signingConfigs.develop

  2. productionRelease并且productionDebug应该只签名signingConfigs.production

另一个与此相似的问题导致我做了以上操作:针对相同productFlavors Firebase的buildTypes(调试和发布)的SHA-1不同?

Man*_*ani 5

删除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

    }
}
Run Code Online (Sandbox Code Playgroud)

在终端中使用以下 gradle 命令: gradle assembleProduction类似地生成具有生产证书的构建,gradle assembleDevelop或者您也可以使用gradle assemble

您不能强制 gradle 选择debug财产证书,而可以创建自己的证书buildTypes

根据文档

自动签署您的应用程序。默认情况下,调试构建变体使用调试密钥进行签名,以便在开发设备上安装。声明其他签名配置以发布到 Google Play 商店。

更新: 正如另一个答案所指出的,

在要调试构建并查看日志的自定义构建类型下添加可调试的 true 属性。