Android Gradle - Add packageNameSuffix to a specific product

I have an Android Gradle project with this product group and flavor configuration:

/* * Define different flavor groups */ flavorGroups 'market', 'version' /* * Defile product flavors */ productFlavors { amazon { flavorGroup 'market' } google { flavorGroup 'market' } flav1 { flavorGroup 'version' packageName 'com.company.flav1' } flav2 { flavorGroup 'version' packageName 'com.company.flav2' } flav3 { flavorGroup 'version' packageName 'com.company.flav3' } } // .. Other stuff 

It works great. All sources and resources are merged correctly. But for specific reasons, I need a .amz package .amz for amazon product flavor. How can i achieve this?

I tried this way:

 amazon { flavorGroup 'market' packageNameSuffix '.amz' } 

but gradle throws an exception.

+6
source share
3 answers

This is currently not possible. packageNameSuffix is ​​strictly a Build Type property.

I would like to suggest a way to adjust ProductFlavor values ​​for this option (i.e., a given combination of all flavor sizes and build type), but this is not possible at the moment.

Instead of a new taste dimension, you can create an "amzRelease" buildtype that extends the existing release build type and adds a suffix.

If your current Amazon fragrance does more (configure versionCode / Name / etc ...), it will not work. Then you can use both your Amazon flavor and the amzRelease build type. This will create a lot more options than you need, but it will work until we succeed.

+11
source

You can use the solution I wrote here: fooobar.com/questions/250935 / ...

In short, you can find merged options using variantFilter and then update applyiationId from there:

 android.variantFilter { variant -> def flavorString = "" def flavors = variant.getFlavors() for (int i = 0; i < flavors.size(); i++) { flavorString += flavors[i].name; } if(flavorString.contains("amazon")) { variant.getDefaultConfig().applicationId variant.getDefaultConfig().applicationId + ".amz" } } 
+1
source

Working solution for gradle 1.0.0 +:

 android.applicationVariants.all { variant -> def flavorName = variant.getVariantData().getVariantConfiguration().getFlavorName() def mergedFlavour = variant.getVariantData().getVariantConfiguration().getMergedFlavor(); if (flavorName.toLowerCase().contains("amazon")) { mergedFlavour.setApplicationId(mergedFlavour.getApplicationId() + ".amz") } } 
0
source

Source: https://habr.com/ru/post/959469/


All Articles