Skip to content

fix: stop crashing at startup on Android 12 (API 31) - #195

Merged
RXWatcher merged 1 commit into
Silo-Server:mainfrom
RXWatcher:fix/spatializer-api32-crash
Aug 7, 2026
Merged

RXWatcher merged 1 commit into
Silo-Server:mainfrom
RXWatcher:fix/spatializer-api32-crash

Conversation

@RXWatcher

@RXWatcher RXWatcher commented Aug 7, 2026 •

Copy link
Copy Markdown
Contributor

The crash

Every Android 12 (API 31) device crashes on launch. Reported from a TiVo Stream
4K running app 1.0.0:

java.lang.NoClassDefFoundError: Failed resolution of: Landroid/media/Spatializer;
  at …AudioCapabilityManager.<init>
  at …  (Koin module definition)

android.media.Spatializer and AudioManager.getSpatializer() were added in
API 32 (S_V2), but AudioCapabilityManager gated on S (31):

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {   // 31 — too low
    runCatching { audioManager.spatializer }.getOrNull()
}

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.
minSdk is 24, so these devices are fully supported, and both the phone and TV
apps 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 Spatializer reference sitting in an
untaken if still throws, and the surrounding runCatching cannot help because
the 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 shape
media3 uses for its own SpatializerWrapper.

Verification

dexdump on the built APK shows only two classes referencing
android/media/Spatializer:

androidx/media3/exoplayer/util/SpatializerWrapper
org/siloserver/silo/common/player/SpatializerBridge

AudioCapabilityManager no longer references it. Behaviour on API 32+ is
unchanged: the same enabled-state read and the same state-change subscription.

Summary by CodeRabbit

  • Bug Fixes
    • Improved spatial audio capability detection on Android 12 and newer.
    • Added safer handling when spatial audio is unavailable or cannot be initialized.
    • Audio capabilities now correctly report spatial audio as disabled when the feature is unsupported, helping prevent playback issues.

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]>
@coderabbitai

coderabbitai Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 067ad065-ffbe-49a8-9939-801a892b2f8a

📥 Commits

Reviewing files that changed from the base of the PR and between c3b2c9b and 34c62ad.

📒 Files selected for processing (1)
  • android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudioCapabilityManager.kt

📝 Walkthrough

Walkthrough

The change isolates Android Spatializer references in an API 32+-only bridge. AudioCapabilityManager uses the bridge for initialization, callbacks, and enabled-state queries with failure handling.

Changes

Spatializer API isolation

Layer / File(s) Summary
Spatializer bridge implementation
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudioCapabilityManager.kt
The new SpatializerBridge owns platform Spatializer access and forwards enabled-state callbacks.
Capability manager integration
android-shared/src/androidMain/kotlin/org/siloserver/silo/common/player/AudioCapabilityManager.kt
AudioCapabilityManager subscribes through the bridge and defaults capability detection to disabled when access fails or is unavailable.

Estimated code review effort: 3 (Moderate) | ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the startup crash fix on Android 12/API 31, which matches the main change.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@RXWatcher
RXWatcher merged commit 25b1d6b into Silo-Server:main Aug 7, 2026
2 checks passed
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant