使用 gradle 签署产品口味 [英] Signing product flavors with gradle

查看:44
本文介绍了使用 gradle 签署产品口味的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力将我的项目迁移到 gradle.我的一个项目有多种产品风格,每个项目都必须在其发布版本中使用不同的 signingConfig 进行签名.所以这是我到目前为止尝试过的:

I am tyring to migrate my projects to gradle. One of my projects has multiple product flavors and each one of them has to be signed with a different signingConfig in its release version. So this is what I tried so far:

buildscript {
    ...
}

apply plugin: 'android'

android {
    compileSdkVersion 17
    buildToolsVersion '17'

    signingConfigs {
        flavor1 {
            storeFile file("keystore")
            storePassword "secret"
            keyAlias "aliasForFlavor1"
            keyPassword "secretFlavor1"
        }

        flavor2 {
            storeFile file("keystore")
            storePassword "secret"
            keyAlias "aliasForFlavor2"
            keyPassword "secretFlavor2"
        }
    }

    productFlavors {
        flavor1 {
            signingConfig signingConfigs.flavor1
        }

        flavor1 {
            signingConfig signingConfigs.flavor2
        }
    }
}

dependencies {
    ...
}

当我运行 gradle build 时,我收到一个 groovy.lang.MissingFieldException 和以下错误消息:

When I run gradle build I get a groovy.lang.MissingFieldException and the following error message:

No such field: signingConfigs for class: com.android.build.gradle.internal.dsl.GroupableProductFlavorFactory

所以我认为 Gradle 脚本的 productFlavors.* 部分不适合放置代码签名配置.

So I assume the productFlavors.* part of the Gradle script is not the right place to put code signing configurations.

推荐答案

根据 用户指南,支持口味的签名配置.

Per the user guide, signingConfigs for flavors are supported.

这里的问题与signatureConfigs 对象的范围有关.我只是将它分配给 productFlavors 块内的变量,但在 flavor1 风味块之外以解决问题:

The problem here has to do with the scope of the signingConfigs object. I just assigned it to a variable inside the productFlavors block, but outside the flavor1 flavor block to fix the issue:

productFlavors {
    def flavor1SigningVariable = signingConfigs.flavor1

    flavor1 {
        ...
        signingConfig flavor1SigningVariable
        ...
    }

这篇关于使用 gradle 签署产品口味的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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