I am using aproach to provide modules to Dagger described in answer of this question Android Customize Workflow for Product Flavors
Our approach is a bit different - we have Modules
in debug
build type in src/debug/java
and in release
build type in src/release/java
. Our main module is called ApplicationModule
it includes all other.
Modules
in src/debug/java
provides some custom behaviour for debugging, logging etc and overrides ApplcationModule
.
Now we have a need to have custom behaviour based on application flavor.
What would be correct approach to do that?
For example flavors A to C should provide custom behaviours, while flavors D to F should provide basic, default behaviour.
So far I came up with such.
- All flavors (not build types) has same class in
src/flavorX/java/com.application.FlavorModule
- To avoid code duplication only flavors A to C provide custom behavior while other completely empty so that project would compile. And default behaviour is provided my module in
src/main/java
Is there a better way to achieve such result? Because I don't like empty src/flavorX/java/com.application.FlavorModule
and don't like code duplication...