Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get ABI name in Gradle outputs iterator

Tags:

android

gradle

I'm composing .apk filename using current app version and flavor name. I'd like to add current ABI split name as well, but only if it's a universal apk.

My relevant build.gradle sections:

buildTypes {
    release {
        applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def flavor = ....  // some code to parse flavor & determine an appropriate string from it
                output.outputFile = new File(output.outputFile.parent, "app_" + flavor + "_0" + variant.versionCode + ".apk")
            }
        }
    }
}
productFlavors {
    deploy {
        splits {
            abi {
                enable true
                reset()
                include 'armeabi-v7a' //select ABIs to build APKs for
                universalApk true //generate an additional APK that contains all the ABIs
            }
        }
    }
}

Currently this config generates two .apks, but they both have the same file name as I don't know how to get the ABI name, so the one generated later overwrites the one generated before.

So, what is the equivalent variant.productFlavors.get(0) for current ABI split?

like image 617
velis Avatar asked Feb 07 '23 05:02

velis


1 Answers

That's very strange as flavor and ABI-name is automatically added to build name (if you make corresponding assemble)

can you try completely remove your custom made naming

 applicationVariants.all { variant ->
            variant.outputs.each { output ->
                def flavor = ....  // some code to parse flavor & determine an appropriate string from it
                output.outputFile = new File(output.outputFile.parent, "app_" + flavor + "_0" + variant.versionCode + ".apk")
            }
        }

and instead of that try to add to defaultConfig this line

 archivesBaseName = "app_${versionCode}"

If this is will not resolve you issues you can try to get abi from output

output.getFilter(com.android.build.OutputFile.ABI)
like image 194
aelimill Avatar answered Feb 13 '23 05:02

aelimill