Skip to content

Conversation

@jmalmo
Copy link

@jmalmo jmalmo commented Oct 1, 2025

fix(android): guard nullable originalItem before Arguments.fromBundle on v4

On Kotlin 2.1.x (e.g., Expo SDK 54 / RN 0.81), RNTP v4 fails to compile due to
a nullability mismatch: Arguments.fromBundle expects a non-null Bundle,
but originalItem is declared as Bundle? in v4.

This change wraps the conversion with a null-safe check so we only call
Arguments.fromBundle when originalItem is non-null. Behavior is unchanged
for JS: when the backing bundle is null, methods still resolve to null.

Before (examples):

  • MusicModule.getTrack: Arguments.fromBundle(musicService.tracks[index].originalItem)
  • MusicModule.getActiveTrack: Arguments.fromBundle(...originalItem)

After:

  • ...originalItem?.let { Arguments.fromBundle(it) }

Why

  • Fixes v4 compilation on Kotlin 2.1.x without altering runtime behavior.

Testing

  • “Test plan”: built lib + example runs on Android emulator; no crashes; compile success.
  • Built Android with Kotlin 2.1.20 / AGP 8.7.x / Gradle 8.14.x.
  • :react-native-track-player:compileDebugKotlin succeeds.
  • App boots on Android emulator (Pixel_9_Pro).
  • Sanity-checked getTrack / getActiveTrack return null when no bundle.

Notes

  • This PR targets the v4 branch (maintenance). main already migrated to
    the new module/codegen and doesn’t exhibit this specific issue.

Closes: #2530

@jmalmo jmalmo changed the base branch from main to v4 October 14, 2025 16:17
@jmalmo
Copy link
Author

jmalmo commented Oct 14, 2025

@mpivchev @dcvz — this touches /android/; could you review when you have a moment? ❤️

@Polarisation
Copy link

It would be helpful to get this merged and released as soon as possible, because all supported versions of React Native now use Kotlin 2.1+ since RN 0.79.x was moved to Unsupported last week.

@brunocroh
Copy link

+1, I solved it by applying a patch on my side, but I’m looking forward to the next release with this fix. Thank you.

@freefugga
Copy link

This works perfectly!!! ❤️

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.

Android (v4.1.2) Kotlin 2.1.x compile error: Bundle? passed to Arguments.fromBundle

5 participants