I wanted to implement a new dynamic feature module in an existing app but had to give up due to product flavor problems.
The example code can be found here. https://github.com/henningBunk/dynamic_feature_problem
I have three modules:
- app. The main module of the app. It has two product flavors:
store
: amazon
and google
pay_status
: free
and pro
Resulting in four combinations:
amazonFree
, amazonPro
, googleFree
and googlePro
It depends on lib
and lists dynamic_feature
as a dynamic feature.
lib. A library module,
app
anddynamic_feature
depend on this module.lib
only has thepay_status
flavor. So when I build eg. the App as thegoogleFree
flavor, lib will build it'sfree
flavor.dynamic_feature. The new feature which shall be a dynmic feature. This module should not have any flavors. It depends on app and lib.
The three gradle files, reduced to product flavors and dependecies look like this:
App module build.gradle:
apply plugin: 'com.android.application'
android {
dynamicFeatures = [":faq"]
flavorDimensions "store", "pay_status"
productFlavors {
google { dimension "store" }
amazon { dimension "store" }
free { dimension "pay_status" }
pro { dimension "pay_status" }
}
}
dependencies {
implementation project(':lib')
}
Lib module build.gradle:
apply plugin: 'com.android.library'
android {
flavorDimensions "pay_status"
productFlavors {
free { dimension "pay_status" }
pro { dimension "pay_status" }
}
}
dependencies {
}
Dynamic feature module build.gradle:
apply plugin: 'com.android.dynamic-feature'
android {}
dependencies {
implementation project(':app')
implementation project(':lib')
}
This results in the error:
ERROR: Unable to resolve dependency for ':dynamic_feature@debug/compileClasspath': Could not resolve project :app.
Show Details
Affected Modules: dynamic_feature
So I read that the module dynamic_feature
might need a missing dimension strategy. Adding
missingDimensionStrategy "store", "google"
missingDimensionStrategy "pay_status", "free"
to the dynamic_feature build.gradle into android.defaultConfig. This way I can build some flavors but not all of them: