Repository navigation
fix: stop crashing at startup on Android 12 (API 31) - #195
Merged
Merged
Conversation
android.media.Spatializer and AudioManager.getSpatializer() were added in API
32 (S_V2), but the guard tested against S (31). On an API 31 device the getter
ran, ART could not resolve the class, and AudioCapabilityManager's constructor
died — during Koin graph creation, so the app crashed on launch and was
unusable. Reported from a TiVo Stream 4K (Android 12, app 1.0.0):
java.lang.NoClassDefFoundError: Failed resolution of: Landroid/media/Spatializer;
Correcting the version constant alone is not enough. ART resolves the classes a
method references when the method runs, before any version branch inside it is
evaluated, so a reference in an untaken 'if' still throws — and the existing
runCatching could not help, because the failure happens outside its try. All
Spatializer access therefore moves into SpatializerBridge, loaded only on API
32+, which is the same shape media3 uses for SpatializerWrapper.
Verified with dexdump: only SpatializerBridge and media3's own wrapper
reference the class in the built APK; AudioCapabilityManager no longer does.
Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe change isolates Android ChangesSpatializer API isolation
Estimated code review effort: 3 (Moderate) | ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
RXWatcher
added a commit
that referenced
this pull request
Aug 7, 2026
* chore: gate API-level mistakes with lint in CI Lint had never run on this project — no config, no baseline, not in CI — and two startup crashes reached users because of it: a Spatializer call gated at API 31 for a class introduced at 32 (#195), and this change fixes the two remaining unguarded calls in the same file. AudioDeviceInfo.getAddress() is API 28 and had no guard at all; it threw NoSuchMethodError on API 24-27 whenever diagnostics were collected. AudioTrack.isDirectPlaybackSupported() is API 29 and was reached on anything below TIRAMISU; runCatching swallowed the error, so pre-Q devices silently reported no passthrough and transcoded audio they could have played directly. The gate itself: NewApi and InlinedApi are fatal, apps set checkDependencies so android-shared is actually analysed — it is where both crashes lived and where app-level lint was blind — and per-module baselines hold the existing findings so only new violations fail. The baselines are almost entirely desugared java.* calls and deliberate media3 @UnstableApi usage. Verified by reintroducing the unguarded getAddress call: the build fails with 'Call requires API level 28 (current min is 24)'. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> * fix(audio): guard eac3_joc behind API 28, and lint the release variant in CI Two gaps left by the lint gate itself. `EncodingSupport` carries a `minSdk` field precisely so an encoding constant is only queried on platforms that have it. `dts_hd`, `truehd` and `ac4` all use it. `eac3_joc` needs API 28 exactly as `ac4` does, and was the one entry left on the default of 1, so API 24-27 queried the platform for an encoding that does not exist there. It could not crash — the constant is inlined, and the platform answers false for a value it does not know — so the result was right by accident in a table where every neighbour is right by design. Lint cannot see this: `InlinedApi` fires on the constant reference, not on the runtime guard, which is why the correctly-guarded `truehd` and `ac4` entries are baselined too. All three baseline entries stay. This is about the code being right, not about silencing lint. The second gap is structural. `checkReleaseBuilds` makes `lintVitalRelease` part of `assembleRelease`, which runs only from release.yml on a v* tag. The release variant was therefore gated by a check no pull request ran, and its first execution would have been mid-release. Adding both vital tasks to the lint job moves that discovery to the PR, and covers the release-only source sets `lintDebug` never analyses. Verified: `:androidApp:lintVitalRelease` and `:androidTvApp:lintVitalRelease` both pass, `:android-shared:lintDebug` reports no new issues, and `:android-shared:testDebugUnitTest` is 1101 tests, 0 failures. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> --------- Co-authored-by: rxwatcher <[email protected]> Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
The crash
Every Android 12 (API 31) device crashes on launch. Reported from a TiVo Stream
4K running app 1.0.0:
android.media.SpatializerandAudioManager.getSpatializer()were added inAPI 32 (
S_V2), butAudioCapabilityManagergated onS(31):On API 31 the getter runs, ART cannot resolve the class, and the constructor
dies inside Koin graph creation — so the app is unusable, not merely degraded.
minSdkis 24, so these devices are fully supported, and both the phone and TVapps are affected because the class lives in
android-shared.Why bumping the constant is not enough
ART resolves the classes a method references when the method runs, before any
version branch inside it is evaluated. A
Spatializerreference sitting in anuntaken
ifstill throws, and the surroundingrunCatchingcannot help becausethe failure happens outside its
try.All Spatializer access therefore moves into a
@RequiresApi(S_V2)SpatializerBridge, which is only loaded on API 32+. This is the same shapemedia3 uses for its own
SpatializerWrapper.Verification
dexdumpon the built APK shows only two classes referencingandroid/media/Spatializer:AudioCapabilityManagerno longer references it. Behaviour on API 32+ isunchanged: the same enabled-state read and the same state-change subscription.
Summary by CodeRabbit