签约的产品口味与摇篮 [英] Signing product flavors with gradle

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

问题描述

我tyring迁移我的项目摇篮。我的一个项目中有多个产品的风味和他们每个人都有用不同的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 {
    ...
}

当我运行摇篮构建我收到了 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

所以我假定productFlavors。*的摇篮脚本的一部分是不正确的地方放code签约配置。

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

推荐答案

按照用户指南,支持signingConfigs的味道。

Per the user guide, signingConfigs for flavors are supported.

这里的问题,是因为有所述signingConfigs对象的范围。我刚分配到了 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
        ...
    }

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

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