react-native-onesignal@5.4.1 fails to compile on Android with React Native 0.79.0. The codegen-generated NativeOneSignalSpec
produces method signatures that don't match the RNOneSignal.java implementation.
Environment
- react-native: 0.79.0
- react-native-onesignal: 5.4.1
- Kotlin: 2.0.21
- Gradle: 8.13
- Android Gradle Plugin: 8.8.2
- newArchEnabled: true
Error
RNOneSignal is not abstract and does not override the abstract method addTriggers(String) in NativeOneSignalSpec
7 methods have mismatched signatures:
| Method |
NativeOneSignalSpec (codegen) |
RNOneSignal.java |
addTriggers |
String |
ReadableMap |
addTags |
String |
ReadableMap |
addAliases |
String |
ReadableMap |
trackEvent (2nd param) |
@Nullable String |
@Nullable ReadableMap |
setupDefaultLiveActivity |
@Nullable String |
@Nullable ReadableMap |
startDefaultLiveActivity (2nd, 3rd params) |
String, String |
ReadableMap, ReadableMap |
Root Cause
The TurboModule JS spec (NativeOneSignal.ts) declares these parameters as string (e.g. addTriggers(triggers: string)), which the
RN 0.79 codegen correctly maps to String on Android. However, the Java implementation in RNOneSignal.java still expects
ReadableMap.
The spec and the Java implementation were not aligned when TurboModule support was added in 5.4.0 (PR #1920).
Additional Issue: Kotlin version mismatch
react-native-onesignal@5.4.1 pulls com.onesignal:OneSignal:5.7.6 which is compiled with Kotlin 2.2.0. React Native 0.79.0 ships
with Kotlin 2.0.21, causing:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 2.0.0.
Workaround
- patch-package to fix the Java method signatures (parse JSON strings to maps internally)
- Pin native SDK to 5.6.2 via Gradle
resolutionStrategy (last version compiled with Kotlin 1.9.x, compatible with 2.0.x)
configurations.all {
resolutionStrategy {
force 'com.onesignal:OneSignal:5.6.2'
force 'com.onesignal:core:5.6.2'
force 'com.onesignal:notifications:5.6.2'
force 'com.onesignal:in-app-messages:5.6.2'
force 'com.onesignal:location:5.6.2'
}
}
react-native-onesignal@5.4.1 fails to compile on Android with React Native 0.79.0. The codegen-generated
NativeOneSignalSpecproduces method signatures that don't match the
RNOneSignal.javaimplementation.Environment
Error
RNOneSignal is not abstract and does not override the abstract method addTriggers(String) in NativeOneSignalSpec
7 methods have mismatched signatures:
addTriggersStringReadableMapaddTagsStringReadableMapaddAliasesStringReadableMaptrackEvent(2nd param)@Nullable String@Nullable ReadableMapsetupDefaultLiveActivity@Nullable String@Nullable ReadableMapstartDefaultLiveActivity(2nd, 3rd params)String, StringReadableMap, ReadableMapRoot Cause
The TurboModule JS spec (
NativeOneSignal.ts) declares these parameters asstring(e.g.addTriggers(triggers: string)), which theRN 0.79 codegen correctly maps to
Stringon Android. However, the Java implementation inRNOneSignal.javastill expectsReadableMap.The spec and the Java implementation were not aligned when TurboModule support was added in 5.4.0 (PR #1920).
Additional Issue: Kotlin version mismatch
react-native-onesignal@5.4.1pullscom.onesignal:OneSignal:5.7.6which is compiled with Kotlin 2.2.0. React Native 0.79.0 shipswith Kotlin 2.0.21, causing:
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 2.2.0, expected version is 2.0.0.
Workaround
resolutionStrategy(last version compiled with Kotlin 1.9.x, compatible with 2.0.x)