Skip to content

Instantly share code, notes, and snippets.



Last active May 24, 2017
What would you like to do?
Adds support for splitted Apkes by abi (arch platform), creates renameApk task (supports the android.split feature), see
apply plugin: ''
//Adds support for splitted Apkes by abi (arch platform)
android {
splits {
// Configures multiple APKs based on ABI.
abi {
// Enables building multiple APKs.
enable true
// By default all ABIs are included, so use reset() and include to specify that we only
// want APKs for x86, armeabi-v7a, and mips.
// Specifies a list of ABIs that Gradle should create APKs for.
include "x86", "armeabi-v7a", "arm64-v8a"
// Specify that we want to also generate a universal APK that includes all ABIs.
universalApk true
//Creates renameApk task (supports the android.split feature)
android.applicationVariants.all { variant ->
variant.outputs.each { output ->
def baseAbi = output.getFilter(OutputFile.ABI)?.capitalize() ?: ""
def baseAbiSuffix = baseAbi.isEmpty() ? baseAbi : "-${baseAbi.toLowerCase()}"
def apkName ="my_apk_name-${variant.versionCode}-${}${baseAbiSuffix}"
output.outputFile = file("${output.outputFile.parent}/${apkName}.apk")
def renameApkTaskName = "renameApk"
task "${renameApkTaskName}${}$baseAbi" {
group "renaming"
description "Renames apk file of the ${} build to apk name with buildId"
dependsOn "assemble${}"
if (!rootProject.tasks.findByName(renameApkTaskName)) {
rootProject.tasks.create(renameApkTaskName) {
group "renaming"
description "Renames apk files of the builds to apk name with buildId"
rootProject.tasks.findByName(renameApkTaskName).dependsOn it
def targetApkName ="$apkName-${buildId}"
def apkFile = output.outputFile
def targetApkFile = file("${output.outputFile.parent}/${targetApkName}.apk")
doLast {
if (!apkFile.exists()) {
throw new GradleException("$apkFile doesn't exist to rename it")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.