Share A Dagger 2 Component Between Two Different Flavors
Solution 1:
When using flavors you should not have different packages for the different components.
Instead of com.xxx.myapp.free.MainActivity
Move MainActivity up a level to com.xxx.myapp.MainActivity
both versions of MainActivity must have the same fully qualified named.
UPDATE
You have two classes named MainActivity
but to Java they have different fully qualified names com.xxx.myapp.free.MainActivity
and com.xxx.myapp.pro.MainActivity
(just a guess).
What you really need is one class com.xxx.myapp.MainActivity
with flavor specific implementations. YOu can add a separate implementation of MainActivity to each flavor by the flavor specific folder paths.
app/src/free/java/com/xxx/myapp/MainActivity.java
app/src/pro/java/com/xxx/myapp/MainActivity.java
Gradle will only compile the implementation for the selected flavor.
Solution 2:
You can determine the flavor at runtime by using BuildConfig.FLAVOR and from there you can selectively add advertisements and what not. I would personally do it this way.
Post a Comment for "Share A Dagger 2 Component Between Two Different Flavors"