Reputation: 8292
I try to make an application for multiple partners and for each partner a test and prod version. For each flavors I create a specific folder with res/values in it like the documentation said.
My gradle file look like this :
apply plugin: 'com.android.application'
android {
packagingOptions {
exclude 'META-INF/LICENSE'
exclude 'META-INF/NOTICE'
}
compileSdkVersion 14
buildToolsVersion "21.1.2"
defaultConfig {
versionCode 1
versionName 1
minSdkVersion 14
targetSdkVersion 19
}
productFlavors {
prodPARTNER1 {
applicationId "com.PARTNER1"
}
testPARTNER1 {
applicationId "com.PARTNER1.test"
}
prodPARTNER2{
applicationId "com.PARTNER2"
}
testPARTNER2{
applicationId "com.PARTNER2.test"
}
}
sourceSets {
testPARTNER2 {
res.srcDirs = ["testPARTNER2/res", "prodPARTNER2/res"]
}
}
}
dependencies {
compile project(':ViewPagerIndicatorLibrary')
compile 'com.android.support:support-v4:19.0.0'
compile 'com.google.android.gms:play-services:+'
compile files('libs/achartengine-1.1.0.jar')
compile files('libs/android-async-http-1.4.4.jar')
compile files('libs/jackson-annotations-2.2.3.jar')
compile files('libs/jackson-core-2.2.3.jar')
compile files('libs/jackson-databind-2.2.3.jar')
compile files('libs/urlimageviewhelper-1.0.4.jar')
}
I want for a test version to take res folder of the prod version (like this I not duplicate resources for both version) and merge it with the test version. The problem is :
Error:Error: Duplicate resources:
C:\...prodPARTNER2\res\values\strings.xml:string/app_name,
C:\...testPARTNER2\res\values\strings.xml:string/app_name
Any idea ? It's not possible to merge too res folder for the same flavors ?
EDIT : I use gradle v 1.1.0 and android studio v 1.1.0 too
Upvotes: 2
Views: 4075
Reputation: 2793
Warning: this approach has changed a little bit on Android Plugin for Gradle 3.0.0
Use productFlavors
for each partner app and define a build type test
for test builds.
productFlavors {
partner1 {
applicationId "com.partner1"
}
partnerN {
applicationId "com.partnerN"
}
}
buildTypes {
debug {
// use defaults
}
release {
// the 'prod' version, use defaults
}
test {
// config as you want!
applicationIdSuffix ".test"
versionNameSuffix " Test"
debuggable true
minifyEnabled false
signingConfig signingConfigs.debug
}
}
You can use mix and match source folders as the Android Plug-in for Gradle shows:
To build each version of your app, the build system combines source code and resources from:
src/main/
- the main source directory (the default configuration common to all variants)src/<buildType>/
- the source directorysrc/<productFlavor>/
- the source directory
Edit: This user guide is another source of help: http://tools.android.com/tech-docs/new-build-system/user-guide
Edit 2: according to the link above:
Additional sourcesets are also created for each variants:
android.sourceSets.flavor1Debug
Locationsrc/flavor1Debug/
android.sourceSets.flavor1Release
Locationsrc/flavor1Release/
android.sourceSets.flavor2Debug
Locationsrc/flavor2Debug/
android.sourceSets.flavor2Release
Locationsrc/flavor2Release/
Then, you can use /src/partner1Test/
to define resources specifics to partner1
flavor AND Test
build, that is a partner1Test
build variant.
Upvotes: 2