Include Library With Flavor Android
Solution 1:
The problem the app has is that it doesn't know which library's flavor to use.
The keyword matchingFallbacks
will tell the app which library's flavor you want to select. But this keyword has to be use with a Flavor.
We have to add a flavor (+ dimension) on your app build.gradle:
android {
...
//flavorDimensions is mandatory with flavors. Use the same name on your 2 files to avoid other conflicts.
flavorDimensions "dim"
productFlavors {
nocustomer{
dimension "dim"
// App and library's flavor have the same name.
// MatchingFallbacks can be omitted
matchingFallbacks = ["nocustomer"]
}
customerNb{
dimension "dim"
// Here the app and library's flavor are different
// Matching fallbacks will select the library's flavor 'customer001'
matchingFallbacks = ["customer001"]
}
}
...
}
dependencies {
implementation project(':zblelib')
}
In this way, when you select the app's flavor nocustomer
, the library's flavor will select automatically nocustomer
, and when you select the app's flavor customerNb
, the library's flavor will select automatically customer001
PS
I am using implementation
instead of compile
, because compile is deprecated (see here)
Solution 2:
You should be using missingDimensionStrategy
in your app's build.gradle
file where it matches the missing flavors from your library. Check migration docs for Gradle 3.0.0 how to implement it.
For your particular problem where your library includes product flavors that the app doesn't check section A library dependency includes a flavor dimension that your app does not.
from the table.
EDIT:
Define flavors in your app's build.gradle
file and then use matchingFallbacks
to specify exactly which flavor you are to match from the libraries.
productFlavors {
paid {
dimension 'tier'
matchingFallbacks = ['customer001', 'nocustomer']
}
free {
dimension 'tier'
matchingFallbacks = ['nocustomer', 'customer001']
}
}
Post a Comment for "Include Library With Flavor Android"