I have an application with a bunch of products that are basically white labels of a single application. However, from time to time there is some discrepancy from the main stream in some kind of taste, because the client wants something a little different. So far, we have edited the code for these cases and used spaghetti code (a lot of ifs and elses) to make sure that other applications do not break. Needless to say, this is not a very scalable (or even normal) way to do this.
One option is to write activity classes in the productFlavor source folders, i.e. src/flavor1/java/AnActivity.java , src/flavor2/java/AnActivity.java etc. Since productFlavor code cannot override src/main classes, this requires that the same classes be copied for each new taste, even if there is no setting. I do not really like this option. This leads to the fact that many redundant codes and class names end up being less descriptive, because they all must have the same name to override others, even if they can do something else.
Another option would be to use something like Dagger to build an ObjectGraph and input Intents for different implementations. For example, if it is flavor1 , when the X button is pressed, the intention for ActivityA is entered, and if it is flavor2 , the intention for ActivityB is entered.
This seems like the best way to do this, but I still don't know how to implement classes that will override the default ObjectGraph .
Any implementation ideas or other options? I am not attached to Dagger , I am just starting to learn injections and dependency testing, so other frameworks work just as well.
android android-intent android-build dagger
Saad farooq
source share