Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set signingConfig for different flavor dimensions?

I'm trying to figure out how can I specify a signingConfig for the individual flavor dimensions generated. I have seen how to do it when using different flavor but not flavor dimensions.

I'm currently applying a different package name for the different flavor dimensions successfully and thought maybe something similar could be done with signingConfig?

> android.applicationVariants.all { variant ->
>     def flavorString = variant.getVariantData().getVariantConfiguration().getFlavorName()
>     def mergedFlavour = variant.getVariantData().getVariantConfiguration().getMergedFlavor();
> 
>     if(flavorString.equalsIgnoreCase("amazonFree")) {
>         mergedFlavour.setApplicationId("com.test.amazon.free")
>     }
>     if(flavorString.equalsIgnoreCase("amazonPro")) {
>         mergedFlavour.setApplicationId("com.test.amazon.pro")
>     }
>     if(flavorString.equalsIgnoreCase("googleFree")) {
>         mergedFlavour.setApplicationId("com.test.google.free")
>     }
>     if(flavorString.equalsIgnoreCase("googlePro")) {
>         mergedFlavour.setApplicationId("com.test.google.pro")
>     } }

My flavor setup

// Special flavor dimensions for different markets and
// versions paid and free.
flavorDimensions 'market', 'version'

productFlavors {
    amazon {
        flavorDimension 'market'
    }
    google {
        flavorDimension 'market'
    }
    // Base free version
    free {
        flavorDimension 'version'
        // Need this cause of all the ad libraries we are using :/
        defaultConfig.multiDexEnabled true

        // For now we sign all free versions with this config
        // cause we have no idea how to sign the individual flavor dimensions.
        signingConfig signingConfigs.googleFree
    }
    // Base pro version
    pro {
        flavorDimension 'version'

        // For now we sign all free versions with this config
        // cause we have no idea how to sign the individual flavor dimensions.
        signingConfig signingConfigs.googlePro
    }
}
like image 806
Jona Avatar asked Apr 03 '15 20:04

Jona


People also ask

What is Flavour dimension?

Flavor dimensions are groupings of product flavors, and you can combine flavors from different dimensions.

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.

How can I get flavor on my android?

You can add a config file, say 'Appconfig. java' to your productFlavor specific source folders i.e. src/<productflavor>/java/<packagename>/Appconfig. java ; you can then use Appconfig. PRODUCT_FLAVOR in your app.

How do I get the current flavor in Gradle?

There is no direct way to get the current flavor; the call getGradle().


1 Answers

First of all applicationId can be applied in productFlavors block itself:

productFlavors {
    amazonFree {
        applicationId 'com.test.amazon.free'
    }
    amazonPro {
        applicationId 'com.test.amazon.pro'
    }
    googleFree {
        applicationId 'com.test.google.free'
    }
    googlePro {
        applicationId 'com.test.google.pro'
    }
}

Signing config can be configured per flavor the same way:

productFlavors {
    amazonFree {
        applicationId 'com.test.amazon.free'
        signingConfig  signingConfigs.amazonFree
    }
    amazonPro {
        applicationId 'com.test.amazon.pro'
        signingConfig  signingConfigs.amazonPro
    }
    googleFree {
        applicationId 'com.test.google.free'
        signingConfig  signingConfigs.googleFree
    }
    googlePro {
        applicationId 'com.test.google.pro'
        signingConfig  signingConfigs.googlePro
    }
}
like image 63
Kirill Boyarshinov Avatar answered Sep 22 '22 14:09

Kirill Boyarshinov