Mohamed Khalifa
Mohamed Khalifa

Reputation: 181

Application Id based on build type

I need to change full application Id based on build type not adding a suffix after Id. I have tried to move applicationId inside each build type but Gradle uses the last one in the last build type by default. Is that possible?

Upvotes: 3

Views: 3820

Answers (3)

Melad
Melad

Reputation: 1224

You can use gradle filter to ignore some build/flavor targets.
Check the following code:

variantFilter { variant ->
   def flavor = variant.flavors*.name
   def buildType = variant.buildType*.name

   // To check for a certain build type, use variant.buildType.name == "<buildType>"
   if ((flavor.contains("xyz") && buildType.contains("debug"))) {
       // Gradle ignores any variants that satisfy the conditions above.
       setIgnore(true)
   }
}

Upvotes: 1

Timur Panzhiev
Timur Panzhiev

Reputation: 760

I use this simple approach and it works well

android {

    ...
    
    applicationVariants.all { variant ->
        if (variant.name.contains("debug")) {
            variant.mergedFlavor.applicationId = "application.id.debug"
        } else {
            variant.mergedFlavor.applicationId = "application.id.release"
        }
    }
}

Upvotes: 1

Ariane Breton
Ariane Breton

Reputation: 1333

In order to change your applicationId you need to change your package in the manifest and in all your directories

  1. Go to top left corner of Android Studio where it says Android
  2. Click on it and change it to Project Files as of Android Studio 3.3
  3. Right next to the side of Project Files click on the gear and Uncheck "Compact Directories"
  4. Open folders -> click on app -> src -> main -> java -> your -> package -> name
  5. Now that you see individual folders, right click the parts that you want to change -> Refactor -> Rename

Then you can change you applicationId and package in your AndroidManifest.xml

Hope it helps

source: Change Application Id Official Android Documentation

Upvotes: 0

Related Questions