Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build type specific folder not recognized for a product flavor

I have configured my project to have multiple product flavors. I have the following code in my module build.gradle:

android {
    // Rest of the configuration omitted for clarity
    buildTypes {
        debug {
            // ...
        }

        release {
            // ...
        }
    }

    productFlavors {
        paid
        free
    }
}

If I create a file (any file: Java, resources, ...), in the paid, free, debug or release, it is recognized by Android Studio and I can use it in my project.

However, if the same file is created in paidDebug (or a similar folder) it is not recognized in Android Studio. Do I need any extra configuration for this to work? Is this not supported (yet)?

like image 494
Gaëtan Avatar asked Mar 10 '23 01:03

Gaëtan


1 Answers

  1. Source code files with the same name should be placed in all of the alternative source sets (but not in the 'main').

    Either:

    app/src/free/java/com/domain/myapp/MainActivity.java
    app/src/paid/java/com/domain/myapp/MainActivity.java

    Or:

    app/src/freeDebug/java/com/domain/myapp/MainActivity.java
    app/src/freeRelease/java/com/domain/myapp/MainActivity.java
    app/src/paidDebug/java/com/domain/myapp/MainActivity.java
    app/src/paidRelease/java/com/domain/myapp/MainActivity.java

  2. Resource files with the same name can be placed in any source set, including 'main'.

    app/src/main/res/layout/activity_main.xml
    app/src/paidDebug/res/layout/activity_main.xml
    app/src/paidRelease/res/layout/activity_main.xml

    In this case, when building the 'free' flavor, the layout file from 'main' set will be used. But, during the build of the 'paid' flavor, the specific version of the layout will be used.

like image 90
dev.bmax Avatar answered Apr 30 '23 11:04

dev.bmax