28
votes

I have created custom buildTypes as follows:

 buildTypes {
        releasefree.initWith(buildTypes.release)
        releasefree {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
        releasepro.initWith(buildTypes.release)
        releasepro {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
            applicationIdSuffix ".pro"
        }
        debugfree.initWith(buildTypes.debug)
        debugfree {
            shrinkResources true
            applicationIdSuffix ".debug"
            debuggable true
        }
        debugpro.initWith(buildTypes.debug)
        debugpro {
            shrinkResources true
            applicationIdSuffix ".pro.debug"
            debuggable true
        }
    }

I am not going to use the default debug and release build types ever and want to remove them from the build variants list. I have more than a few flavors and the list of variants is too huge. Removing the variants with default debug and release types will help as I'm never going to use them.

I tried using variant filter as follows but it did not work

android.variantFilter { variant ->
    if(variant.buildType.name.endsWith('Release') || variant.buildType.name.endsWith('Debug')) {
        variant.setIgnore(true);
    }
}

Is there something wrong in the way I'm filtering the variants or is it just not possible to remove the variants with default debug and release build types.

3

3 Answers

33
votes

Figured it out. It was a really silly mistake on my part. The above variant filter does work. The names are all lower case and the upper case in the strings i was comparing with were the culprit.

Changing to the following (making compare strings lower case) made it work as expected:

android.variantFilter { variant ->
    if(variant.buildType.name.endsWith('release') || variant.buildType.name.endsWith('debug')) {
        variant.setIgnore(true);
    }
}

or this

android.variantFilter { variant ->
    if(variant.buildType.name.equals('release') || variant.buildType.name.equals('debug')) {
        variant.setIgnore(true);
    }
}
2
votes

If u want exclude by name use something like this

android.variantFilter { variant ->
    if(variant.name.equals("qaRelease")|| variant.name.equals('something')) {
        variant.setIgnore(true);
    }
}
0
votes

If you want to ignore specific build variant , Here is details for understanding.

flavorDimensions "client", "server"
productFlavors {
    client1 {
        manifestPlaceholders variant : 'Client 1'
        dimension "client"
        applicationId "com.edupointbd.bb"
    }
    client2 {
        manifestPlaceholders variant : 'Client 2'
        dimension "client"
        applicationId "com.edupointbd.bb"
    }
    dev {
        dimension "server"
    }
    staging {
        dimension "server"
    }
    production {
        dimension "server"
    }
}

variantFilter { variant ->
    def names = variant.flavors*.name
    // To check for a certain build type, use variant.buildType.name == "<buildType>"
    if (names.contains("client1") && names.contains("production")) {
        // Gradle ignores any variants that satisfy the conditions above.
        setIgnore(true)
    }
}