androidgradleandroid-ndkabibuild-variant

ABI filters of extended Build Variants do not overrides its parents


In a project i need specific ABI filters per release and debug and some extneded build variants. It is ok and works fine with debug and release.

 release {
.
.
.
    ndk {
        abiFilters 'armeabi'
        }

}
debug {
.
.
.
    ndk {
        abiFilters 'x86', 'x86_64', 'armeabi'
        }
}

When i extend new buildvariant that init each of these tow variants, abifilters is remained and do not change. For example i have debug_on_mainserver that inits debug. but i want to add another abiFilter. But it is still use debug abiFilters.

debug_on_mainserver {
    initWith(buildTypes.debug)
    .
    .
    .
    ndk {
        abiFilters 'armeabi'
        }
}

I should say that may i can achive this with Flavor but i use 3 flavor for another reason (store type and handle store config and variables) and i do not want to add another flavor and mulitple my buildVariants variety. Beacuse it is logically should include in debug_on_mainserver. How i can exclude or remove base abiFilters and add new one? Or is it another way to achive this?


Solution

  • You can achieve what you want by adding abitFilters.clear() like so:

    debug_on_mainserver {
        initWith(buildTypes.debug)
        .
        .
        .
        ndk {
            abiFilters.clear()
            abiFilters 'armeabi'
        }
    }
    

    The reason this is necessary is because abiFilters 'string' is not a setter for abiFilters; it adds 'string' to the existing MutableSet<String> of ABI filters, which is inherited from the parent build type.