Different keyStore for different product flavors in Gradle

productflavors
android build variants vs flavors
android flavor dependencies
android studio build variants not showing
flavordimensions default
android variantfilter
flavor in build gradle
android gradle dependencies

I have different productFlavors specified in my build.gradle file

 dev {
            applicationId "com.advancedprogressive.chare.dev"
            versionCode 83
            versionName "2.2.1"
        }
staging {
            applicationId "com.advancedprogressive.chare.qa"
            versionCode 119
            versionName "2.8.1"
        }

and have have signing configurations like

signingConfigs {
        release {
            storeFile 
            storePassword 
            keyAlias 
            keyPassword         }
        debug {
            keyPassword 
            storeFile 
            keyAlias 
            storePassword 
        }
    }

I have different keystors for both flavors. I can specify different keystores for different build types e.g debug/release but how can i specify different keysotre for each flavor.

You can use somenthing like this:

android {
    signingConfigs {
        dev {
        }

        staging {
        }
    }

    productFlavors {
        dev {
            signingConfig signingConfigs.dev
        }

        staging {
            signingConfig signingConfigs.staging
        } 
    }
}

Signing product flavors with gradle, You can declare signing config for each flavor in buildType . Here is my gradle file for release signing flavors with different keystores. android  For some purposes, I create three different targets for production and testing env. Only production config has signingConfig which means: in this case, I don’t care about staging/rc build.

Using below gradle you can achieve multiple productFlavors :

   android {
  signingConfigs {
    release {
        keyAlias 'alias'
        keyPassword 'password'
        storeFile file('first.keystore')
        storePassword 'password'
    }

    debug {
        keyAlias 'alias'
        keyPassword 'password'
        storeFile file('second.keystore')
        storePassword 'password'
    }
  }

  compileSdkVersion 23
  buildToolsVersion "23.0.2"
  defaultConfig {
        minSdkVersion 14
        targetSdkVersion 23
     }

      productFlavors{
        dev {
            applicationId "com.advancedprogressive.chare.dev"
            versionCode 83
            versionName "2.2.1"
            signingConfig signingConfigs.debug 
        }
        staging {
            applicationId "com.advancedprogressive.chare.qa"
            versionCode 119
            versionName "2.8.1"
            signingConfig signingConfigs.release
        }
  }

      }

I hope its help you.

How to use Gradle on multi-keystore/flavors project?, After adding that signingConfigs, all you need to do is to add different Second one is used to add signingConfig setting into product flavor  Plugin to simplify creation of JKS keystores via a key, cert, and an intermediate PKCS12 keystore. Gradle Plugin. official gradle plugin page; Examples. Java Spark Framework. demonstrates plugin's flexibility in running via IDE and generating Docker images; Description. This plugin will add the following gradle tasks, the arrows indicate the

After searching on the internet I found no clear example anywhere. I tried this and it finally worked!

In your app/build.gradle file
android{
    signingConfigs {
        free {
            def keystorePropertiesFile = rootProject.file("app/src/free/keystore.properties")
            def keystoreProperties = new Properties()
            keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }

        paid {
            def keystorePropertiesFile = rootProject.file("app/src/paid/keystore.properties")
            def keystoreProperties = new Properties()
            keystoreProperties.load(new FileInputStream(keystorePropertiesFile))

            keyAlias keystoreProperties['keyAlias']
            keyPassword keystoreProperties['keyPassword']
            storeFile file(keystoreProperties['storeFile'])
            storePassword keystoreProperties['storePassword']
        }
    }

    ...

    flavorDimensions "default"
    productFlavors {
        free {
            applicationId "com.example.freeapp"
            versionCode 1
            versionName "1.0"
            signingConfig signingConfigs.free

        }
        paid {
            applicationId 'com.example.paidapp'
            versionCode 1
            versionName '1.0'
            signingConfig signingConfigs.paid
        }
    }
}
In your app/src/flavor_name/keystore.properties
storePassword=...
keyPassword=..
keyAlias=...
storeFile=src/flavor_name/keystore_file.jks //or any other path of jks file

Configure build variants, Build variants are the result of Gradle using a specific set of rules to combine For example, a "demo" product flavor can specify different features and devices and configures APK signing with a generic debug keystore. After the sync completes, Gradle automatically creates build variants based on your build types and product flavors, and names them according to <product-flavor><Build-Type>. For example, if you created "demo" and "full" product flavors, and kept the default "debug" and "release" build types, Gradle creates the following build variants:

Create different keystore for different flavour in Gradle , Create different keystore for different flavour in Gradle Android productFlavors{ SGPROD{ applicationId "com.mobile.sg" buildConfigField  Product Flavors do the same: the output of the project becomes all possible combinations of Build Types and, if applicable, Product Flavors. Each (Build Type, Product Flavor) combination is called a Build Variant. For instance, with the default debug and release Build Types, the above example generates four Build Variants: Flavor1 - debug

Auto switch signing configs for multiple-releases-product · GitHub, Auto switch signing configs for multiple-releases-product. build.gradle. apply from​: 'release.gradle'. android{. productFlavors {. dev {. // } // } signingConfigs {. Flavor Dimensions is a way to group flavors by a name. For now, we’re using just a single group. Add the following line in your defaultConfig block: flavorDimensions "default". Now syncing the gradle would give you the following product flavors: Android Build Variants combine build types and product flavors.

Generate and deploy multiple flavor APKs in a single workflow , You can generate, code sign and deploy multiple flavor (multi-flavor) APKs in Check out the official Android Studio guide on build types, flavors and build variants for more info! Check out how you can upload your keystore file to bitrise.io. Recently, I experienced product flavors in Android development and it is fantastics feature. I want to give you some keywords and what they means basically. When you create a new module, Android…

Comments
  • How would you specify a signing config for stagingRelease but not stagingDebug ?
  • got it. now how can i specify if build should be debug able or not. where should i place "debuggable" flag
  • You can get your answer here : run/debug release version of app