用flavor签名配置覆盖调试构建类型签名配置 [英] Override debug build type signing config with flavor signing config

查看:165
本文介绍了用flavor签名配置覆盖调试构建类型签名配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有2种风格的Android应用:内部 production ,并且还有2种构建类型: debug release .

I've got an Android app that has 2 flavors: internal and production, and there are 2 build types as well: debug and release.

我正在尝试根据风味分配签名配置,根据文档所述,这是可行的.我查看并找到了其他答案,但是似乎没有一个可行.一切都可以编译,但是正在使用我的计算机本地的调试密钥库对应用程序进行签名.

I'm trying to assign signing configs based on the flavor, which according to the documentation is doable. I've looked and found other answers to this, but none of them seem to work. Everything compiles, but the app is being signed with the debug keystore local to my machine.

这是我的gradle文件:

Here is my gradle file:

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0.0"
    }

    signingConfigs {
        internal {
            storeFile file("../internal.keystore")
            storePassword "password"
            keyAlias "user"
            keyPassword "password"
        }
        production {
            storeFile file("../production.keystore")
            storePassword "password"
            keyAlias "user"
            keyPassword "password"
        }
    }

    productFlavors {
        internal {
            signingConfig signingConfigs.internal
            applicationId 'com.test.test.internal'
        }
        production {
            signingConfig signingConfigs.production
            applicationId 'com.test.test'
        }
    }

    buildTypes {
        debug {
            applicationIdSuffix ".d"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    variantFilter { variant ->
        if (variant.buildType.name.equals('debug')
                && variant.getFlavors().get(0).name.equals('production')) {
            variant.setIgnore(true);
        }
    }
}

注意:我还使用 classpath'com.android.tools.build:gradle:1.1.3'

推荐答案

似乎默认情况下,Android在调试版本类型(Android调试密钥库)上以及当将 signingConfig 设置为构建类型,将忽略 signingConfig 的样式.

It seems that by default, Android has a signingConfig set on the debug build type (the android debug keystore), and when the signingConfig is set for the build type, the signingConfig is ignored for the flavor.

解决方案是在调试构建类型上将 signingConfig 设置为 null .然后将使用为风味提供的 signingConfig 代替:

The solution is to set the signingConfig to null on the debug build type. Then the signingConfig given for the flavor will be used instead:

buildTypes {
        debug {
            // Set to null to override default debug keystore and defer to the product flavor.
            signingConfig null
            applicationIdSuffix ".d"
        }
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

这篇关于用flavor签名配置覆盖调试构建类型签名配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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