I am looking for informations about how I should use gradle flavors to define my behaviors for an Android Application.
Let's say I want to start a new activity in my flavor1 and not in my flavor2.
As gradle doesn't override classes with each other,
I have to, define the Activity in each flavors
app/src/
|-> flavor1/java/<package>/Activity.java
|-> flavor2/java/<package>/Activity.java
|-> main/java/<package>
or, define it in my main folder and use an enum in a Constant class which return if I am in my flavor1 or my flavor2
app/src/
|-> flavor1/java/<package>/Constant.java
|-> flavor2/java/<package>/Constant.java
|-> main/java/<package>/Activity.java
My guess is that I have to mix both solutions:
throw RuntimeException("stub!")
main
, I have to use something like if (Constant.getFlavor() == flavor1)
In my opinion, this is the coolest way to use gradle flavors. But I want to be sure that there is no other best ways, so far discovered, to deal with it before the final implementation.
Is there anyone who blogged something about it or want to give his own opinion ? I would love to read you!
Thanks in advance!
You can place different AndroidManifest files on each flavor. For example you can define the (let's call it) optional Activity inside the flavor1, the Class that extends the optional Activity just inside the flavor1 and you're done! Please note that the flavor AndroidManifest file must specify only what is different from the main AndroidManifest: in this case, you should include just the <activity/>
(of course inside an empty <application/>
)