Search code examples
androidbuild.gradleandroid-productflavors

What to do to update import class for Flavor build?


I'm writing an Android application with two build flavor. I'm using class with same name in both flavor and this class launched by common code placed in main/src/.

Now question is, is there way to update import-class reference when choose build flavor!! I have idea about Android-studio setting but this just not work until you remove old-import. Any suggestion !!


Solution

  • Android Studio gradle projects can contain different source sets to build the application from. Especially every build type and every flavor has its own source set defined, which gets merge automatically with the main source set.

    You cannot change the import statement for different flavors, but you can use these different source sets to have different implementations for the same class. You only have to make sure, not to put these classes into the main source set, but in every mutually exclusive source set, i.e. in debug and release or in flavor1 and flavor2.