Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

signingConfig has to be different per flavor and build type

Tags:

android

gradle

I have two different applications in the same Android Studio project. I have two flavor 'flavor1' and 'flavor2' with three different build types 'staging', 'debug' and 'release'

The problem is that I need to use a different key store per each application.

Now I have this, but it only sign with the same key store.

signingConfigs {
    release {
        def Properties props = new Properties()
        def propFile = new File('./signing.properties')
        if (propFile.canRead()) {
            props.load(new FileInputStream(propFile))

            if (props != null && props.containsKey('STORE_FILE')
                    && props.containsKey('STORE_PASSWORD')
                    && props.containsKey('KEY_ALIAS')
                    && props.containsKey('KEY_PASSWORD')) {
                android.signingConfigs.release.storeFile = file(props.getProperty('STORE_FILE'))
                android.signingConfigs.release.storePassword = props.getProperty('STORE_PASSWORD')
                android.signingConfigs.release.keyAlias = props.getProperty('KEY_ALIAS')
                android.signingConfigs.release.keyPassword = props.getProperty('KEY_PASSWORD')
            } else {
                println 'signing.properties found but some entries are missing'
                android.buildTypes.release.signingConfig = null
            }
        } else {
            println 'signing.properties not found'
            android.buildTypes.release.signingConfig = null
        }
    }
} 

buildTypes {
    staging {
        debuggable true
        signingConfig android.signingConfigs.debug
    }
    debug {
        debuggable true
        signingConfig android.signingConfigs.debug
    }
    release {
        debuggable false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        signingConfig signingConfigs.release
        minifyEnabled false
    }
}
like image 496
beni Avatar asked Jul 08 '15 14:07

beni


People also ask

When would you use product flavor in your build setup?

123 let's go Simply put, a product flavor is a variant of your app. It is very useful when you want to create multiple versions of your app. This means you can generate different versions or variants of your app using a single codebase.

What are build flavors?

Android Product Flavors are also known as Android build types or Android build variants are the native Android app development way to implement different versions of the same application with minor changes.

What means build type?

Build Type refers to build and packaging settings like signing configuration for a project. For example, debug and release build types. The debug will use android debug certificate for packaging the APK file. While, release build type will use user-defined release certificate for signing and packaging the APK.


1 Answers

You can create flavor specific signing configs:

An example:

   signingConfigs {
        flavor1Release {
            storeFile file('home/keys/flavor1keystore.keystore')
            storePassword 'keystorePassword'
            keyAlias 'alias'
            keyPassword 'aliasPassword'
        }
        flavor2Release {
            storeFile file('home/keys/flavor2keystore.keystore')
            storePassword 'keystorePassword2'
            keyAlias 'alias2'
            keyPassword 'aliasPassword2'
        }
   }

And then in your flavor, select the correct signing config:

  productFlavors {
        def flavor1SigningVariable = signingConfigs.flavor1Release
        def flavor2SigningVariable = signingConfigs.flavor2Release

        flavor1 {
            signingConfig flavor1SigningVariable
        }
        flavor2 {
            signingConfig flavor2SigningVariable
        }
 }
like image 187
biddulph.r Avatar answered Nov 12 '22 22:11

biddulph.r



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!