I need three flavors:
fake
staging
prod
fake
will provide classes like FakeUser
, FakeUserDb
- it's very important that these classes are not compiled into the prod
flavor.
prod
and staging
are completely identical, except that I need to compile a different String url
into prod
vs staging
.
So, I need to create an "abstract" real
flavor that both prod
and staging
inherit.
This can be easily done with the android gradle plugin, but how can I do it in a pure java gradle module?
Creating Product Flavor is pretty much easy in Android Studio, we simply need to add productFlavors block inside the Android block in the application-level build. gradle file. It's that simple to create product flavors.
There is no "current flavor". The Gradle build file is building an object model of the build process. It is not an interpreted script only being used once a build is underway and a "current flavor" is known.
You can add a config file, say 'Appconfig. java' to your productFlavor specific source folders i.e. src/<productflavor>/java/<packagename>/Appconfig. java ; you can then use Appconfig. PRODUCT_FLAVOR in your app.
Android Studio uses Gradle, an advanced build toolkit, to automate and manage the build process, while allowing you to define flexible custom build configurations. Each build configuration can define its own set of code and resources, while reusing the parts common to all versions of your app.
I wrote a gradle-java-flavours plugin to do this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With