Search code examples
android-studio-3.0android-gradle-3.0

How to override versionCode for ABI filters with gradle plugin 3.0.0-beta1?


I have the following defined in my build.gradle for overriding the versionCode based on the ABI.

import com.android.build.OutputFile

android.applicationVariants.all { variant ->
    variant.outputs.each { output ->
        def defaultCode = android.defaultConfig.versionCode
        def filter = output.getFilter(OutputFile.FilterType.ABI)
        def abiMultiplier = project.ext.versionCodes.get(filter)
        if (abiMultiplier == null) {
            abiMultiplier = 1
        }
        output.versionCodeOverride = abiMultiplier * 100000000 + defaultCode
    }
}

This works with the 2.3 gradle plugin, but not with Android Studio 3.0 beta 1, using 3.0.0-beta1 gradle plugin with gradle 4.1, giving me the follow error:

Could not find method getFilter() for arguments [ABI] on ApkVariantOutputImpl_Decorated{apkData=FullSplit{type=FULL_SPLIT, fullName=developmentArm64-v8aDebug, filters=[FilterDataImpl{type=ABI, value=arm64-v8a}]}} of type com.android.build.gradle.internal.api.ApkVariantOutputImpl.

The migration documentation seems to indicate that this might be somewhat broken? I've tried also tried:

def filter = output.getFilter(ApkVariantOutput.ABI)

and casting output to ApkVariantOutput to no avail (same error).


Solution

  • The solution was to change OutputFile.FilterType.ABI to OutputFile.ABI, which uses the string representation of the FilterType enum.