Android Studio : How to remove/filter build variants for default debug and release buildTypes and keep only those using custom buildTypes?

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);
    }
}

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);
    }
}