I want to create different versions of my application based on different products, but you need a certain degree of flexibility that I canβt reach yet.
This is my folder structure:
+src +main +java +res +base +java +res +custom1 +java +res +custom2 +res
The common code is on the main (service), and the ui base is on the basis (activity). Then the user version of the application defining the new ui is on custom1 (new activity). This is working fine. But I need another version of the application ( custom2 ) that uses base ui, but changes some parameters (icons, lines or colors).
What I'm trying in the build.gradle file:
android{ ... productFlavors { base { ... } custom1 { ... } custom2 { ... } } sourceSets{ custom2{ java.srcDirs = ['src/base/java'] res.srcDirs = ['src/custom2/res', 'src/base/res'] } } }
To indicate that custom2 will use the source code and base resources and custom2 resources.
The problem is that I get a:
Error: Duplicate resources: <project_path>/src/base/res/values-es/strings.xml:string-en/app_name, <project_path>/src/custom2/res/values-es/strings.xml:string-en/app_name
Since app_name defined both on the base and on custom2 , but my goal is to override the definition of resources in the database using <those custom2 .
I know that app_name will be overridden in main if I don't specify anything in res.srcDirs for custom2 , but then all resources from base will be unavailable.
Is the approach right? or am I abusing the flexibility that Gradle offers? or is there a way to do what I'm trying to do?
Thanks in advance!
android android-studio build.gradle gradle android-productflavors
Parmaia
source share