Search code examples
javaandroidgradlebuild

gradle, how to exclude particular class in a flavor build apk


I have a projekt with 3 flavors for Android

1 class i need in two of the flavor but the other one should not implement it.

Is ther a way to exclude this java class for only one flavor or did i have to move the class in both other flavors and get rendundant code this way?


Solution

  • If you have some sources which you don't want to be compiled, Then you have to declare a filter for the sources, not for the class files.

    So your gradle configuration will be look like below:

    SetOfSources {
        main {
            java {
                include 'com/macao/somePackage/activityAdapter/**'
                include 'com/macao/someOtherPackage/**'
                exclude 'com/macao/someOtherPackage/pollingAdapter/**'
                exclude 'com/macao/someOtherPackage/matchingAdapter/**'
            }
        }
    }