I have a Gradle Android project that has 4 product flavors (each has it\'s own unique package name). The build.gradle
file is prity much straightforward:
You can use some sort of inheritance AndroidManifest.
The following rules are used when dealing with all the sourcesets used to build a single APK:
- All source code (src/*/java) are used together as multiple folders generating a single output.
- *Manifests are all merged together into a single manifest. This allows Product Flavors to have different components and/or permissions, similarly to Build Types.*
- All resources (Android res and assets) are used using overlay priority where the Build Type overrides the Product Flavor, which overrides the main sourceSet.
- Each Build Variant generates its own R class (or other generated source code) from the resources. Nothing is shared between variants.
code:
productFlavors {
flav1 {
packageName 'com.company.flav1'
versionName calcVersion()
}
flav2 {
packageName 'com.company.flav2'
versionName calcVersion()
}
flav3 {
packageName 'com.company.flav3'
versionName calcVersion()
}
flav4 {
packageName 'com.company.flav4'
versionName calcVersion()
}
}
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aild.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
flav1 {
manifest.srcFile 'flavor1/AndroidManifest.xml'
}
flav2 {
manifest.srcFile 'flavor2/AndroidManifest.xml'
}
...
}
Where flavor1
and flavor2
are folders in root project folder.
In flavor1/AndroidManifest.xml
In flavor2/AndroidManifest.xml
And in root AndroidManifest
everything else.