So this is a bit interesting, I'm unsure how exactly to set it up in android studio. I have several modules that have some re-usable components I use in various apps, however it would be nice to inject certain themes into the reusable components using flavors. Rather than create a new flavor for every component for every app I write, I was thinking of having 1 Theme module, that would have a flavor per app I write, that has color schemes...etc. Here is kind of how I want it set up:
App1: dependencies reusable lib1 reusable lib3 reusable lib4 theme - App1 flavor App2: dependencies reusable lib1 reusable lib2 reusable lib4 theme - App2 flavor
Now I would prefer if the reusable libs could simply depend on theme without needing to know which flavor to build, and the main app proj in it's dependency on theme could reference the flavor for that app (using this answer https://stackoverflow.com/a/24316133/1316346). The reason for this is each reusable module can't have a single app in it's build.gradle dependencies or it would break other apps referencing them. It's also tedious to have to make a flavor of each reusable module for every app I write. Is there any way to achieve something like this? Here's what I tried:
App1 build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(path: ':Theme', configuration: 'app1Release')
compile project(':Lib1')
compile project(':Lib2')
compile project(':Lib4')
}
App2 build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(path: ':Theme', configuration: 'app2Release')
compile project(':Lib1')
compile project(':Lib3')
compile project(':Lib4')
}
Lib1 build.gradle:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(path: ':Theme')
}
The problem with this is as soon as Lib1 tries to access anything in theme, it get's an error. In fact it doesn't even build theme first, it will attempt to build Lib1 before Theme even though Lib1 has a dependency (something weird with the flavors). If I change Lib1 to:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.1.1'
compile project(path: ':Theme', configuration: 'app1Release')
}
It will work for app1, but I'd have to either constantly change it prior to building each app, or do lots of flavors for each lib I'd like to avoid. Anybody ever achieve anything like this?
tl;dr Can a module reference a flavor of another module based on the flavor built by the app referencing the same module