Skip to content

Instantly share code, notes, and snippets.

@ultraon

ultraon/build.gradle.txt

Last active May 24, 2017
Embed
What would you like to do?
Adds support for splitted Apkes by abi (arch platform), creates renameApk task (supports the android.split feature), see https://developer.android.com/studio/build/gradle-tips.html
apply plugin: 'com.android.application'
//...
//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.
reset()
// 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)
import com.android.build.OutputFile
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}-${variant.name}${baseAbiSuffix}"
output.outputFile = file("${output.outputFile.parent}/${apkName}.apk")
def renameApkTaskName = "renameApk"
task "${renameApkTaskName}${variant.name.capitalize()}$baseAbi" {
group "renaming"
description "Renames apk file of the ${variant.name} build to apk name with buildId"
dependsOn "assemble${variant.name.capitalize()}"
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")
}
apkFile.renameTo(targetApkFile);
}
}
}
}
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.