跪拜 Guibai
← All articles
Android

The Day I Rejected Flutter and Still Couldn't Explain the Android Framework

By 疯华整猫 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Android 16's recreation behavior hits every UI stack equally, because the host Activity is still an Activity; engineers who can't trace which layer owns a bug end up gambling on gray release instead of locating it in an hour.

Summary

When Android 16's large-screen configuration changes start recreating Activities by default, a health app's report page loses in-progress notes and double-submits. The immediate fix is moving state from an async callback into saved state. But the deeper realization hits during a review meeting: the author's own argument against rewriting the page in Flutter rests on platform capabilities like PdfRenderer and memory clearing, which Flutter can't replace - yet they couldn't articulate which layer actually decides an Activity's fate.

The article untangles the word "Framework" into two meanings (system source vs. app architecture) and maps a single fold event across six observation points, from user perception to AOSP source. It shows that switching UI stacks only replaces the top two of six layers; lifecycle, permissions, insets, and system services remain. A Channel call is similarly dissected into six places, proving the bridge isn't free.

The core argument: Flutter and Framework are different asset types, not competitors. Flutter's declarative mindset transfers to Compose and other UI, while Framework knowledge is about understanding the platform as a state machine. The author proposes three questions for any stack decision, a twelve-item platform capability checklist, and practical learning paths starting with L1 verification actions, plus measured numbers from a real Add-to-App case.

Takeaways
— Android 16 makes large-screen devices (min width > 600dp) recreate Activities on orientation and size changes by default when targeting API 36; opt-out exists only for target 36 and is expected to be removed in API 37.
— The state-loss bug came from writing a ViewModel field inside an async callback; the callback hadn't returned when recreation happened, so onSaveInstanceState didn't cover it.
— A single fold event can be observed at six levels: user, app logs, dumpsys activity, dumpsys window, AOSP ActivityTaskManagerService, and the app's own code.
— Flutter replaces the UI toolkit layer (layer 2) but not the app framework, system services, runtime, or graphics kernel layers; FlutterActivity is still an Activity subject to the same lifecycle rules.
— A Channel call passes through six places: Dart code, standard codec, Engine/JNI, app framework, system services/Binder, and graphics/kernel; switching stacks only rewrites the first two.
— Android 9 (API 28) restricted non-SDK APIs by list; hidden API reflection is no longer a viable path, but the ability to explain platform behavior has become more valuable.
— Switching UI stacks increases APK size: a nearly blank Flutter release APK was ~7MB larger than a minimal native one (single build, AGP 8.2.2, minSdk 24).
— First-entry time in an Add-to-App campaign page went from 210/260ms P50/P90 to 380/520ms cold; state loss went from 0 to 3 then fixed; Channel methods went from 0 to 5 then 2.
— AOSP's official hardware requirement is 400GB disk and 64GB RAM; a 72-core machine builds in ~40 minutes, a 6-core machine in ~6 hours.
— The author recommends a three-question filter for stack decisions: which layer to replace, which ledgers remain, and what kind of problem you'll be evaluated on for the next three years.
Conclusions

Platform contracts are getting finer while abstraction layers get thicker; the leaks in the abstraction are exactly where someone who understands the contract is needed, so switching frameworks doesn't eliminate platform knowledge requirements.

Flutter's most portable skill is the declarative rebuild mindset, which carries over to Compose, SwiftUI, and React; the framework-specific API details depreciate quickly.

A judgment based on a single 2019 performance observation was treated as a permanent law for six years; re-testing old conclusions against new engine changes like Impeller is more valuable than chasing new frameworks.

The numbers commonly cited in hiring debates count unrelated things: developer surveys, app store analyses, vendor self-reports, and job descriptions; none individually supports a career decision.

Responsibility for platform behavior rarely appears in job descriptions; the person who can trace a crash to the right layer is the one people find on release day.

Upgrade risk is driven by four unsynchronized version lines (targetSdk, AGP, Kotlin/Compose, Flutter SDK, and third-party SDKs); separating them into individual PRs reduces the variables in any single failure.

Concepts & terms
targetSdk
The API level an app declares it is adapted to. Android uses it to select behavior changes, such as whether large-screen configuration changes trigger Activity recreation. Raising it can alter runtime behavior of existing code.
Non-SDK interface (hidden API) restriction
A policy since Android 9 that blocks access to internal platform APIs not in the public SDK, enforced by lists like `blocked`, `max-target-x`, and `unsupported`. It closed the reflection-based pluginization and hot-fix techniques popular before 2018.
Platform Channel
The bridge in Flutter that lets Dart code call native platform APIs (and vice versa). It introduces serialization and thread-switching overhead, and crossing it means the call lands in one of the platform layers that switching stacks can't replace.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗