一键导入
binary-size-reduction
Shrink APK/AAB and IPA size with R8/ProGuard, dead-code elimination, asset hygiene, and Android App Bundle / App Thinning best practices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Shrink APK/AAB and IPA size with R8/ProGuard, dead-code elimination, asset hygiene, and Android App Bundle / App Thinning best practices.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Schedule, batch, and constrain background work with WorkManager, BGTaskScheduler, and push-over-poll patterns to minimize battery and data cost.
Attribute battery drain to CPU, radio, GPS, display, and background work using Android Battery Historian and Xcode Energy Log / Instruments Energy gauge.
Cut local and CI build times on Android (Gradle config cache, build cache, KSP over KAPT) and iOS (Xcode build cache, ccache, modules). Use when clean builds exceed ten minutes.
Downsample, cache, and choose the right image format (AVIF, HEIC, WebP) to cut memory, network, and decode time on iOS and Android.
Find and fix common memory leaks caused by listeners, closures, singletons, and lifecycle mismatches on iOS, Android, Flutter, and React Native.
Capture and analyze heap dumps on Android (Android Studio Profiler, LeakCanary) and iOS (Instruments Allocations/Leaks). Use when memory-related crashes or growth are suspected.
| name | binary-size-reduction |
| description | Shrink APK/AAB and IPA size with R8/ProGuard, dead-code elimination, asset hygiene, and Android App Bundle / App Thinning best practices. |
Binary size affects install conversion, update friction, and in emerging markets, whether the app is installed at all. Cut with a combination of code shrinking, asset hygiene, and store delivery features.
| Platform | Download (p50 device) | On-disk |
|---|---|---|
| Android (AAB download split) | ≤ 25 MB | ≤ 80 MB |
| iOS (thinned download) | ≤ 60 MB | ≤ 150 MB |
android {
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}
}
gradle.properties:
android.enableR8.fullMode=true
Full mode enables aggressive optimizations, horizontal class merging, and method inlining. Expect 10–25% additional shrink on a typical modern app.
Keep rules narrow. Every -keep class com.example.** line prevents shrink on that tree.
Good:
-keepclassmembers class * {
@com.squareup.moshi.FromJson *;
@com.squareup.moshi.ToJson *;
}
Bad (overly broad):
-keep class com.example.** { *; }
Audit with build/outputs/mapping/release/usage.txt — it lists everything R8 kept.
Ship AAB, not APK. Play's Dynamic Delivery slices per ABI, density, and language.
Use Dynamic Feature Modules for rarely-used features (onboarding, premium flows).
Play Asset Delivery for large assets (ML models, tilesets) — do not bundle in the base module.
Remove unused languages: in build.gradle,
android {
defaultConfig {
resConfigs("en", "es", "fr", "de", "ja", "pt", "ru", "zh")
}
}
abiFilters = setOf("arm64-v8a", "armeabi-v7a"). Avoid x86/x86_64 unless you target emulators.-Wl,-z,max-page-size=16384.Ensure Build Settings:
DEAD_CODE_STRIPPING = YES
STRIP_INSTALLED_PRODUCT = YES
DEPLOYMENT_POSTPROCESSING = YES
GCC_OPTIMIZATION_LEVEL = s // Swift: -Osize
SWIFT_OPTIMIZATION_LEVEL = -Osize
Swift -Osize often saves 5–10% over -O.
mozjpeg at q=82.exiftool -all=.Gradle task to detect unused resources:
./gradlew lintDebug | Select-String "UnusedResources"
Android:
./gradlew bundleRelease
# open with Android Studio -> Build -> Analyze APK
The APK Analyzer breaks down .dex size per package. Look for:
okio twice).Play Asset Delivery.iOS: open the .ipa in the Organizer or unzip and inspect:
unzip -l App.ipa
du -sh Payload/App.app/Frameworks/*
Large .framework entries often come from analytics SDKs; evaluate whether you can swap for smaller alternatives.
Flutter: flutter build appbundle --analyze-size produces a size report JSON plus a DevTools view.
React Native: npx react-native-bundle-visualizer and Hermes .hbc inspection.
Fail CI if APK size grows > 2% without an opt-in flag. Store the mapping file and the size-report.json per release.
GitHub Action example:
- name: Fail on APK regression
run: scripts/compare-apk-size.sh artifacts/app-release.aab
-keep ** entries.-Osize; dead code stripping on.