Exclude code from being built/compiled through gradle variants (Android)

Viewed 116

Is there a way to exclude code from being built/compiled through gradle build-variants ? My goal is not to obfuscate the code or having to different behaviours with build variables and if statements. I really want to exclude the code completely and not maintaining 2 code branches.

Sample: I have a gradle file with 2 build variants:

buildTypes {
    versionWithCodeSnipped{

    }
    versionWithoutCodeSnipped{

    }
}

I have some Code I like to be excluded from built.

public void someMethod() {
    <someCode>

    <code snipped to be excluded in case of versionWithoutCodeSnipped>

    <someCode>
}

How to exclude the code above with build variants ?

0 Answers
Related