简体   繁体   English

使用flavor签名配置覆盖调试构建类型签名配置

[英]Override debug build type signing config with flavor signing config

I've got an Android app that has 2 flavors: internal and production , and there are 2 build types as well: debug and release . 我有一个有两种风格的Android应用程序: internalproduction ,还有2种构建类型: debugrelease

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. 所有内容都会编译,但应用程序正在使用本机的本地调试密钥库进行签名。

Here is my gradle file: 这是我的gradle文件:

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);
        }
    }
}

Note: I'm also compiling with classpath 'com.android.tools.build:gradle:1.1.3' 注意:我也在使用classpath 'com.android.tools.build:gradle:1.1.3'编译classpath 'com.android.tools.build:gradle:1.1.3'

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. 这似乎在默认情况下,Android有一个signingConfig的调试版本类型设置(Android的调试密钥库),并在signingConfig设置为构建类型, signingConfig被忽略了的味道。

The solution is to set the signingConfig to null on the debug build type. 解决方案是在调试构建类型signingConfig设置为null Then the signingConfig given for the flavor will be used instead: 然后将使用为flavor设置的signingConfig

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'
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM