Setting Up Android App Bundle (AAB) for Size Optimization
Since August 2021, Google Play requires AAB instead of APK for new applications. But simply switching build format from APK to AAB — insufficient for real size reduction. Need to understand how Google Play Asset Delivery works, configure splits and remove from base module everything that shouldn't be there.
How AAB Reduces Size
APK — single file for all devices. AAB — archive with modules, from which Google Play builds optimized APK for specific device. Samsung Galaxy S23 with arm64-v8a and xxhdpi screen gets only arm64-v8a native libraries and xxhdpi resources — without x86, armeabi-v7a and xhdpi/hdpi variants.
Downloaded APK size reduces on average 15–35% compared to universal APK — official Google data for real applications.
Configuration in build.gradle
android {
bundle {
language { enableSplit = true } // separate APK per language
density { enableSplit = true } // separate APK per screen density
abi { enableSplit = true } // separate APK per CPU architecture
texture {
enableSplit = true
defaultFormat = "ETC2" // baseline format for Mali/Adreno
// ASTC for flagships with support (Adreno 530+, Mali-G51+)
}
}
}
texture splits — especially important for games and 3D apps: ETC2 — universally supported (GLES 3.0+), ASTC — best compression on modern devices, DXT/S3TC — for x86 (ChromeOS). Without texture splits all formats packed together, can add +50–100 MB to size.
Size Check Through bundletool
bundletool build-apks --bundle=app.aab --output=app.apks \
--ks=keystore.jks --ks-pass=pass:password \
--ks-key-alias=key --key-pass=pass:password
bundletool get-size total --apks=app.apks \
--device-spec=pixel7_spec.json
device-spec.json for specific device obtained through bundletool get-device-spec --adb=<path>. Gives exact size of downloadable APK for target device before uploading to Play Store.
R8 and ProGuard — Mandatory Companions to AAB
buildTypes {
release {
minifyEnabled = true
shrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
}
}
shrinkResources = true works only with minifyEnabled = true. Removes unused resources — strings, images, layouts — based on static code analysis. In real projects adds 5–20 MB additional reduction.
R8 in full mode (don't add -dontobfuscate for release) more aggressively removes code and inlines methods. proguard-android-optimize.txt instead of proguard-android.txt enables additional optimizations.
Size Analysis Through Android Studio
Build → Analyze APK (works with AAB through unpacking). Shows pie chart: classes.dex, res/, lib/, assets/. Immediately see what takes most space. Typical findings:
-
assets/with uncompressed JSON data files — compress or move to binary format (Protobuf / FlatBuffers) -
lib/with native libraries for all ABI includingx86andx86_64— keep onlyarm64-v8aandarmeabi-v7afor production build -
res/drawable-*with PNG where VectorDrawable enough
Timeframe
AAB setup with bundletool verification — 1–2 days. For full size optimization including R8 tuning and texture splits — 3–5 days.







