Android override file for flavour

956 views Asked by At

In my android app I have a file that I want to override for a specific flavor. My structure: Structure

However when I build the funki flavour I still see that the Computer class from main is used. In my build.gradle I have:

productFlavors {
    somename{
        resValue "string", "app_name", "some name"
    }
    funki {
        resValue "string", "app_name", "Funki App"
        applicationIdSuffix ".funki"

    } 
}

Every build I see that the Computer file from main is used. All the other overrides e,g, res files are overriden based on the flavor i build. How can I override a class for a specific flavor?

2

There are 2 answers

0
Sven van den Boogaart On BEST ANSWER

I ended up checking the productflavor inside the code like:

if(BuildConfig.FLAVOR.equals("funki")){

Based on the if/else I execute my desired code.

0
CommonsWare On

You should be getting a "duplicate class" build error — at least, that used to be the behavior. You cannot override a Java/Kotlin class in a flavor.

What you can do is remove the Java/Kotlin class from the main source set and have it in all of your flavors. So, move Computer.java from main to somename, and keep your other Computer.java in funki.