build_slim 0.4.0
build_slim: ^0.4.0 copied to clipboard
A CLI tool and library to analyze and reduce the size of Flutter APK, AAB, and IPA build artifacts using best-practice optimizations.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.4.0 - 2026-06-25 #
Added — advanced size strategies #
--aggressiveflag: opt-in bundle of destructive optimizations. Every change ships with a.bakbackup so users can roll back. Without the flag,build_slimkeeps its historical, fully-safe behaviour.- PNG/JPEG → WebP conversion (
WebPConverter): converts raster assets to WebP viacwebpand rewrites the references inlib/**/*.dartandpubspec.yaml. Atomic: if any conversion fails, no references are touched and the originals are preserved. - R8 full mode (
android.enableR8.fullMode=true): injected intoandroid/gradle.propertieswith backup. Removes substantially more unreachable code than the default safe mode. - Strict resource shrinking (
res/raw/keep.xmlwithtools:shrinkMode="strict"): created only when absent; existing keep rules are never overwritten.
- PNG/JPEG → WebP conversion (
--localesflag + auto-detection: injects AndroidresConfigsso third-party AARs (Play Services, AndroidX) no longer drag dozens of unusedvalues-xxfolders into the artifact. Locales are auto-detected from*.arbfiles and iOS.lprojdirectories when the flag is omitted.FindingSeverity.criticalandFinding.breaking: new model fields surfaced by the console/HTML reporters with distinct styling so users immediately spot high-impact issues and changes that may break the build.
Added — passive findings (analyze-only safe) #
- Heavy GIF audit: GIFs above 300KB are flagged as
criticalrecommending Lottie/Rive vector animations. - Font subsetting recommendation:
.ttf/.otffiles above 200KB emit a warning suggestingpyftsubset(a 600KB Latin font typically drops to ~30KB). - Target-aware
extractNativeLibsguidance: AAB targets now recommendextractNativeLibs="false"(Play Store requirement for uncompressed native libs); APK/legacy targets preserve the previous warning. No more contradictory advice. - Deferred import suggestions: heavy packages imported eagerly in
lib/emit an info finding recommendingimport ... deferred as ...so App Bundles can ship them as on-demand splits. - R8 full mode audit (
--analyze-only): reports when the flag is missing, even without running the optimizer.
Changed #
OptimizerPipeline.runandProjectAnalyzernow accept the buildtargetso target-aware findings can be emitted. Thetargetparameter is optional on the analyzer to preserve backwards compatibility for direct callers.pubspec.yamlversion bumped to0.4.0.
0.3.0 - 2026-06-22 #
Fixed #
- Android optimizer now emits correct Kotlin DSL when patching
build.gradle.kts. Previously it injected Groovy syntax (['arm64-v8a', ...]list literals,abiFilters.addAll(...), and bareminifyEnabled/shrinkResources) that failed to compile under the Kotlin DSL.abiFiltersnow usesndk { abiFilters += listOf("arm64-v8a", "armeabi-v7a") }.- Property names use the
isprefix (isMinifyEnabled,isShrinkResources). - Release-only scoping: edits are confined to the
release { ... }build type via brace matching, so a precedingdebug {}block is never mutated. - Word-boundary matching prevents the substring corruption that produced
invalid identifiers like
isminifyEnabled. Re-running the optimizer also repairs files corrupted by previous versions.
NativeConfigAnalyzer.hasGradleBoolnow recognizes the Kotlinis-prefixed property form (isMinifyEnabled = true) so analyze and optimize agree.
Added #
- Release signing resolution for Android targets (
apk,aab) via a newSigningConfigurator. Follows the standardandroid/key.propertiespattern with a deterministic, flag-driven flow (no interactive prompt — CI friendly).--keystore,--store-password,--key-alias,--key-passwordgenerateandroid/key.propertiesfrom a keystore.--signing-config debugtemporarily signs the release build with the debug keystore (validation only) and creates a.bakbackup.- Warns when
key.propertiesis not covered by.gitignore. - Fails fast with actionable guidance when signing is unresolved.
Changed #
OptimizerPipeline.runandFakeOptimizerPipeline.runaccept the new signing parameters (keystore,storePassword,keyAlias,keyPassword,debugSigning). Callers that overriderunmust add the new parameters.- Android optimizer applies patches to whichever Gradle file was found and names it explicitly in the applied-optimizations message.
0.2.0 - 2026-06-21 #
Added #
- Comprehensive test suite: 279 tests covering all analyzers, optimizers, reporters, builders, CLI commands, and utilities (up from 17).
- End-to-end CLI tests that exercise the real
dart --versionandflutter --versionprobes against a fixture project. @visibleForTestinghelpers onNativeConfigAnalyzer(normalizeGradle,hasGradleBool,parseVersion) to enable direct testing of fragile parsing.- Injectable sink (
StringSink? sink) onLoggerto capture log output in tests without spawning real I/O. - Optional dependency injection on
OptimizeCommand,ReportCommand, andBuildSlimRunnerfor unit and integration testing of the CLI. MockProcessRunnerimprovements:responseForcallback,RecordedInvocationrecords (with working directory tracked separately),throwIfUnmatched.FakeOptimizerPipelinetest helper.- Pinned tests documenting known bugs (dead ternary in asset analyzer,
non-monotonic
_parseVersionfor minor >= 100, Groovy-syntax detection gap,_compressWithadding success message on failure).
Changed #
Loggerconstructor is no longerconst(accepts a runtimestdoutsink by default). Existing call sites usingconst Logger(...)should drop theconstkeyword.
0.1.0 - 2024-06-19 #
Added #
- Initial release of
build_slim. optimizecommand to analyze and build APK, AAB, and IPA artifacts.reportcommand to compare before/after artifact sizes.- Asset analyzer that detects unused assets and over-declared font weights.
- Dependency analyzer that flags known heavy transitive packages.
- Native configuration analyzers for Android (
build.gradle) and iOS (Podfile,.xcconfig,.pbxproj). - Dart optimizer that injects
--tree-shake-icons,--obfuscate, and--split-debug-info. - Android optimizer that patches Gradle settings and verifies ProGuard rules.
- iOS optimizer that injects safe
.xcconfigsettings and emits manual instructions. - Asset optimizer that compresses PNG/JPEG/WebP assets when
pngquant,optipng, orcwebpare available. - Console, JSON, and HTML reporters.
- Comprehensive unit tests and fixture project for analyzers.