Flutter Rotation ANR After Hybrid Composition: The Deadlock and the Fix
Developers shipping Flutter on Android can now avoid a UI hang that occurs when rotating after a Hybrid Composition view has closed. With Android 16/17 dropping forced portrait lock, rotation is no longer a rare edge case, so this fix matters for real-world apps.
After an HC PlatformView leaves the page, the Raster thread splits back from the Android main thread, but SurfacePool can retain overlay layers from the old frame size. On the next resize (rotation, fold, split-screen), Raster calls DestroySurfaces() and synchronously waits for the Platform thread, while the Platform thread may be waiting on Raster for getBitmap() or surfaceChanged. The resulting two-way wait freezes the app.
PR #196255 decouples the two sides: Raster releases its GPU surfaces and Vulkan swapchain directly through ReleaseOverlayLayers() without waiting, while the Java ImageReader teardown is posted asynchronously with a pending_java_destroy_ flag. Tests on a Pixel 8 (Android 14/API 34, Impeller Vulkan) show the resize+getBitmap() deadlock drops from 20/20 to 0/20, and Raster's p50 draw time falls from 81.76ms to 15.51ms.
The same deadlock pattern hit HCPP, fixed earlier in #190638 by resizing persistent overlays in place. Flutter 3.47.9 remains vulnerable on both paths; 3.50.0 addresses HCPP only, and legacy HC gets the fix on master. Android 16/17's move to ignore portrait lock makes rotation more common, raising the stakes for this fix.
The deadlock arises because the engine treats surface destruction as a synchronous cross-thread operation; decoupling GPU and Java resource lifetimes removes the dependency that lets the two threads wait on each other.
The benchmark numbers show that before the fix, Raster spent most of its time during resize waiting for the platform thread's latch; after the fix, draw time dropped by over 80%, revealing that the synchronization overhead dwarfed actual GPU work.
The same root cause appearing in both legacy HC and HCPP indicates a systemic design flaw in the external view embedder, not an isolated platform quirk.
Android 16/17's willingness to ignore user portrait lock means any Flutter app still on 3.47.9 is just one rotation away from this ANR on newer devices.