Fix NoSuchMethodError: WindowMetrics.getDensity() crash on launch - #3053
Merged
Conversation
MainActivity derived the window size class with material3's calculateWindowSizeClass(activity), which routes through androidx.window's WindowMetricsCalculator and calls WindowMetrics.getDensity(). That method is absent on some Android 14 builds, so the app crashed on launch with NoSuchMethodError before the first frame. Compute the WindowSizeClass from Configuration (screenWidthDp / screenHeightDp) via WindowSizeClass.calculateFromSize, which never touches androidx.window. Verified on the R8-minified staging build: the material3 AndroidWindowSizeClass path is stripped from the shipped dex. The only residual getDensity reference is Compose UI's lazy LocalWindowInfo.containerSize path, which no app code reads. Firebase Crashlytics issue: 6a11e58b371ac16c7a6781fc95171530 Affected version: 14.4.2 (1786360451)
panasetskaya
approved these changes
Aug 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The app crashes on launch on some Android 14 devices, before the first frame:
MainActivityderived the window size class with material3'scalculateWindowSizeClass(activity). That routes through androidx.window'sWindowMetricsCalculator, which callsWindowMetrics.getDensity(). That method is not present on some Android 14 platform builds, so the call links to nothing at runtime and throwsNoSuchMethodErrorduring initial composition. The library gates the call at API 34 but relies on a method only present in a later Android 14 revision.androidx.window:window:1.5.0is pulled in transitively viamaterial3-window-size-class:1.5.0-alpha17(from thejetbrains-material3 = 1.11.0-alpha07stack).Fix
Compute the
WindowSizeClassfromConfiguration(screenWidthDp/screenHeightDp) viaWindowSizeClass.calculateFromSize, which readsResources.getConfiguration()and never touches androidx.window.A guard comment at the call site documents why we avoid both
calculateWindowSizeClass(activity)andLocalWindowInfo.containerSize(the latter routes through the same androidx.window density path in Compose UI 1.11.4).Verification
Built the R8-minified staging APK and inspected the shrunk dex +
mapping.txt:AndroidWindowSizeClass_androidKt(the crashing path) is stripped from the shipped app: the reported crash cannot recur.WindowMetrics.getDensity()reference is Compose UI's lazyLocalWindowInfo.containerSizepath. It is computed only on read, and no app code readscontainerSize(custom navigation, no material3 adaptive APIs), so it never executes.Scope note
This removes the live trigger of the buggy androidx.window code without pinning the dependency. If the app later adopts Compose adaptive-layout APIs that read
containerSize, the underlying androidx.window bug would resurface and pinningandroidx.windowwould then be warranted.Firebase Crashlytics issue:
6a11e58b371ac16c7a6781fc95171530Affected version: 14.4.2 (1786360451)