Search code examples
androidgradlekeysignandroid-productflavors

why do i have to sign qa flavor in gradle?


i have this build config in my gradle file ?

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
        debug {
            applicationIdSuffix ".debug"
            versionNameSuffix ".debug"
        }
        qa {
            applicationIdSuffix ".qa"
            versionNameSuffix ".qa"
        }
    }
    sourceSets { debug { res.srcDirs = ['src/debug/res', 'src/debug/res/values'] } }
}

why when i am try to run qa it trow me and error for not having key for this flavor ?


Solution

  • The only build type for which Gradle can build your project "out of the box" is debug, as the Android Plugin for Gradle knows to use the plugin-created debug signing keystore. For everything else, you either need to:

    • Configure a separate signing keystore (e.g., for release)

    • Initialize the new build type from the debug build type, akin to using a copy constructor, so it uses the same rules that debug does for signing

    In the following sample, I want to define a new mezzanine build type, giving it the same signing configuration as I use for release. So, I use mezzanine.initWith(buildTypes.release) to set up mezzanine as a copy of release, then continue to configure it with different rules:

    apply plugin: 'com.android.application'
    
    android {
        compileSdkVersion 19
        buildToolsVersion "21.1.2"
    
        defaultConfig {
            versionCode 2
            versionName "1.1"
            minSdkVersion 14
            targetSdkVersion 18
        }
    
        signingConfigs {
            release {
                storeFile file('HelloConfig.keystore')
                keyAlias 'HelloConfig'
                storePassword 'laser.yams.heady.testy'
                keyPassword 'fw.stabs.steady.wool'
            }
        }
    
        buildTypes {
            debug {
              applicationIdSuffix ".d"
              versionNameSuffix "-debug"
            }
    
            release {
                signingConfig signingConfigs.release
            }
    
            mezzanine.initWith(buildTypes.release)
    
            mezzanine {
                applicationIdSuffix ".mezz"
                debuggable true
            }
        }
    }
    

    In your case, you would use something like qa.initWith(buildTypes.debug) before configuring the rest of the qa build type.