-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Description
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
- Create an Expo app (SDK 54; React Native 0.8').
- npm i [email protected]
- npx expo prebuild --platform android (if not already prebuilt)
- npx expo run:android
- 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.)