beerBear
beerBear

Reputation: 979

Multiple Product Flavors of a Single App

I was looking at 'product flavors' on android dev pages and want to explore my options as I have to transform an existing app into an app which is easily modifiable according to needs of multiple clients.

Thinking of that I tried introducing a product flavor but whenever I try to run it after 1-2 activities the screen is left blank with the default background in place and I get a lot of class def not found errors on my adb console.

my project's structure looks like this:

/app/src/main/
/app/src/main/assets/
/app/src/main/java/
/app/src/main/jniLibs/
/app/src/main/res/
/app/src/main/AndroidManifest.xml

/app/src/productflavor/
/app/src/productflavor/res
/app/src/productflavor/res/values/
/app/src/productflavor/res/values/strings.xml

This strings.xml ^ just has one change which works fine which is to change 'app_name' value to change the app's name.

As of now what I am thinking is that the files from 'main' source directory get included (combined?) with the files from the flavor's branch so shouldn't the files from main be available to a product flavor's directory automatically?

Regarding the class def not found errors at runtime:

- if I copy paste all the resources i.e. all the image/string etc. assets from the 'res' folder into the flavor's res directory the that would defeat the purpose of having a common code base and introduce code redundancy

- should I make the existing code as a module and then just have my independent product flavor(s) (i.e. nothing in /app/src/main/*) and use the compile tag in gradle to compile and include the module as is? I think then I can use custom layout files within a particular flavor but if in future I need to make changes to the features of the app for a particular flavor within existing classes then how am I going to make sure it works and does not affect functionality of other flavor(s)?

Upvotes: 0

Views: 642

Answers (1)

Joopkins
Joopkins

Reputation: 1644

The way to handle product flavors is to keep any resources the flavors share in the main directory, but anything they have different must be separated out into each flavor's respective directory. If you have something flavor specific in an activity, then you must remove it from /main and place the two versions in each flavors equivalent directory.

Upvotes: 0

Related Questions