Reputation: 181
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
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
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
Reputation: 1333
In order to change your applicationId you need to change your package in the manifest and in all your directories
- Go to top left corner of Android Studio where it says Android
- Click on it and change it to Project Files as of Android Studio 3.3
- Right next to the side of Project Files click on the gear and Uncheck "Compact Directories"
- Open folders -> click on app -> src -> main -> java -> your -> package -> name
- 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