I am tyring to migrate my projects to gradle. One of my projects has multiple product flavors and each one of them has to be signed with a different signingConfig
in its release version. So this is what I tried so far:
buildscript { ... } apply plugin: 'android' android { compileSdkVersion 17 buildToolsVersion '17' signingConfigs { flavor1 { storeFile file("keystore") storePassword "secret" keyAlias "aliasForFlavor1" keyPassword "secretFlavor1" } flavor2 { storeFile file("keystore") storePassword "secret" keyAlias "aliasForFlavor2" keyPassword "secretFlavor2" } } productFlavors { flavor1 { signingConfig signingConfigs.flavor1 } flavor1 { signingConfig signingConfigs.flavor2 } } } dependencies { ... }
When I run gradle build
I get a groovy.lang.MissingFieldException
and the following error message:
No such field: signingConfigs for class: com.android.build.gradle.internal.dsl.GroupableProductFlavorFactory
So I assume the productFlavors
.* part of the Gradle script is not the right place to put code signing configurations.
This means you can generate different versions or variants of your app using a single codebase. Product flavors are a powerful feature of the Gradle plugin from Android Studio to create customised versions of products. They form part of what we call Build Variants.
Once the new project is created, by default it consists of two build types/variants - debug, release. Debug is the build type that is used when we run the application from the IDE directly onto a device. A release is the build type that requires you to sign the APK.
Change the build variant By default, Android Studio builds the debug version of your app, which is intended for use only during development, when you click Run. To change the build variant Android Studio uses, select Build > Select Build Variant in the menu bar.
You use same core ingredients to make the base but will use different toppings for each one to have a different taste. Similarly, android apps can have the same base functionalities with changes to some of the features like styles, logo etc. This can be achieved using product flavours.
You can declare signing config
for each flavor
in buildType
. Here is my gradle file for release signing flavors with different keystores.
android { signingConfigs { configFirst { keyAlias 'alias' keyPassword 'password' storeFile file('first.keystore') storePassword 'password' } configSecond { keyAlias 'alias' keyPassword 'password' storeFile file('second.keystore') storePassword 'password' } } compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { minSdkVersion 14 targetSdkVersion 23 } productFlavors{ flavor1 { applicationId "com.test.firstapp" } flavor2 { applicationId "com.test.secondapp" } } buildTypes { release { productFlavors.flavor1.signingConfig signingConfigs.configFirst productFlavors.flavor2.signingConfig signingConfigs.configSecond minifyEnabled true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } }
buildTypes
block should be placed after productFlavors
block, I mean order is important.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With