0

I have the same structure as the code below and I want to put prefix to the applicationId and suffix without dots and use the applicationId value at the end within the gradle file.

I don't want to use applicationIdSuffix because it add dots automatically and I can't get it's value on gradle neither the complete applicationId.

flavorDimensions "type", "version"

productFlavors.all {
       ext.appIdPrefix = "com.example"
       ext.appId = ""
       ext.appIdSuffix = ""
    }

productFlavors {

        flavor1 {
            dimension "type"
            appId = ".flavor1"
        }

       full {
            dimension "version"
            appIdSuffix = "Full"
        }
}

productFlavors.all  {
     applicationId appIdPrefix + appId + appIdSuffix
}

Now when I run my app with "flavor1full" the applicationId is "com.exmaple.flavor1" only and doesn't get the value of appIdSuffix

How I can solve that ?

Moaz Rashad
  • 1,035
  • 1
  • 10
  • 16

2 Answers2

1

Instead of changing app ID for each flavor, try to iterate over applicationVariants:

applicationVariants.all { variant ->
    def flavors = variant.productFlavors
    variant.mergedFlavor.applicationId = flavors[0].appId + flavors[1].appIdSuffix ;
}

This will iterate through every combination of flavors twice because of the two build types. See also Multi-Dimension Flavor ApplicationId

Also note a typo in your question: appIdSuffix "Full" should be appIdSuffix="Full"

Zbynek
  • 412
  • 4
  • 17
0

Assuming your ultimate goal is to build different app flavors with different app IDs, you should be able to use something like this:

flavorDimensions "type"

productFlavors.all {
    ext.appIdPrefix = "prefix"
    ext.appId = "hello.world"
}

productFlavors {
    partial {
        dimension "type"
        ext.appIdSuffix = "suffix1"
    }

    full {
        dimension "type"
        ext.appIdSuffix = "suffix2"
    }
}

productFlavors.all {
    applicationId appIdPrefix + "." + appId + "." + appIdSuffix
}

The above will produce you application IDs ending with suffix1 or suffix2 depending on build variant chosen. Not sure I understand why you need another dimension for that.

ror
  • 3,295
  • 1
  • 19
  • 27
  • Yes, but the problem with multiple dimension. if full assigned to another dimension and doing changes to third variable in ext. it will not appear in the applicationId – Moaz Rashad Feb 20 '19 at 13:36