A Gradle plugin to measure the app size impact of Android libraries
Updated Requirements
apkscale
now requires Android Gradle Plugin 7.0.0+, Gradle 7.0.0+, and Java 11Enhancements
humanReadable
configuration property that enables a user to toggle the use of apkanalyzer
--human-readable
flag. This property is true
by default.apkscale {
humanReadable = false
}
Bug Fixes
Enhancements
This release marks the first iteration of apkscale: a Gradle plugin to measure the app size impact of Android libraries.
com.android.library
project.Add the following to your project's buildscript section.
buildscript {
repositories {
jcenter()
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}
classpath "com.twilio:apkscale:0.1.0"
}
Apply the plugin in your Android library project.
apply plugin: 'com.android.library'
apply plugin: 'com.twilio.apkscale'
apkscale {
// Optional parameter to provide size reports for each ABI in addition to the default universal ABI
abis = ['x86', 'x86_64', 'armeabi-v7a', 'arm64-v8a']
}
Apkscale adds a measureSize
task to your Android library module and, when run, scans the output directory of your library and measures the size of each .aar file present. Apkscale outputs the size report to a json file located at <yourProjectBuildDir>/apkscale/build/outputs/reports/apkscale.json
. The json file contains an array of elements that provide a size report for each .aar file measured. Apkscale writes the size in a --human-readable
format as specified by apkanalyzer. Reference the example below.
[
{
"library": "your-library-release.aar",
"size": {
// Included in all reports
"universal": "21.9MB",
// Included as specified by the abis parameter
"x86": "6MB",
"x86_64": "6.1MB",
"armeabi-v7a": "4.8MB",
"arm64-v8a": "5.7MB"
}
}
]
The following demonstrates how to read the Apkscale output and convert it to a markdown table.
task generateSizeReport {
dependsOn('measureSize')
doLast {
def sizeReport = "Size Report\n" +
"\n" +
"| ABI | APK Size Impact |\n" +
"| --------------- | --------------- |\n"
def apkscaleOutputFile = file("$buildDir/apkscale/build/outputs/reports/apkscale.json")
def jsonSlurper = new JsonSlurper()
def apkscaleOutput = jsonSlurper.parseText(apkscaleOutputFile.text).get(0)
apkscaleOutput.size.each { arch, sizeImpact ->
videoAndroidSizeReport += "| ${arch.padRight(16)}| ${sizeImpact.padRight(16)}|\n"
}
println(sizeReport)
}
}