Skip to content

Android (v4.1.2) Kotlin 2.1.x compile error: Bundle? passed to Arguments.fromBundle — request target branch for v4 backport PR #2530

@jmalmo

Description

@jmalmo

Describe the Bug
On Android with Kotlin 2.1.x (Expo / RN 0.81), RNTP v4.1.2 fails to compile due to a nullability mismatch: Arguments.fromBundle expects a non-null Bundle, but originalItem is Bundle? in v4.1.2.

Compiler output (examples):

e: .../node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt:548:51
   Argument type mismatch: actual type is 'Bundle?', but 'Bundle' was expected.
e: .../node_modules/react-native-track-player/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt:588:17
   Argument type mismatch: actual type is 'Bundle?', but 'Bundle' was expected.

A tiny change fixes it for Kotlin 2.1.x without changing behavior: coerce the nullable bundle to a non-null Bundle() before passing into Arguments.fromBundle.

Steps To Reproduce

  1. Create an Expo app (SDK 54; React Native 0.8').
  2. npm i [email protected]
  3. npx expo prebuild --platform android (if not already prebuilt)
  4. npx expo run:android
  5. Build fails at :react-native-track-player:compileDebugKotlin with the errors above.

Code To Reproduce
This is a library compile error (no app code required). For completeness, a minimal app that imports RNTP also reproduces it:

import TrackPlayer from 'react-native-track-player';
export default function App() { return null; }

Replicable on Example App?
Yes—if the example app is bumped to Kotlin 2.1.x (and corresponding AGP), the same error appears during :react-native-track-player:compileDebugKotlin.

Environment Info:

  • React Native: 0.81.4 (Expo SDK 54)
  • Gradle: 8.14.3
  • react-native-track-player: 4.1.2
  • Device: Android Emulator (Pixel_9_Pro)
  • Host OS: macOS (Apple Silicon)

How I can Help
I can open a PR with the following v4 backport patch (works on Kotlin 2.1.x):

diff --git a/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt b/android/src/main/java/com/doublesymmetry/trackplayer/module/MusicModule.kt
@@
-            callback.resolve(Arguments.fromBundle(musicService.tracks[indexInt].originalItem))
+            callback.resolve(
+                Arguments.fromBundle(musicService.tracks[indexInt].originalItem ?: Bundle())
+            )
@@
-        callback.resolve(
-            musicService.currentTrack?.let {
-                Arguments.fromBundle(it.originalItem)
-            }
-        )
+        callback.resolve(
+            musicService.currentTrack?.let {
+                Arguments.fromBundle(it.originalItem ?: Bundle())
+            }
+        )

Request: I don’t see a public 4.x maintenance branch. Which branch should I target for a v4 patch PR (e.g., release/4.x)? I’ll push the PR immediately once you point me to the correct base.

(Related: on bridgeless, v4’s annotation-based module can also trigger TurboModuleInteropUtils$ParsingException when @ReactMethod sync flags don’t match signatures. If helpful, I can prepare a second v4 fix aligning those annotations. I understand main has moved to codegen and likely doesn’t need it; this would just help v4 users.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions