Skip to content

Android build fails with RN 0.79 — RNOneSignal method signatures don't match codegen NativeOneSignalSpec #1936

@Jora4e

Description

@Jora4e

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

  1. patch-package to fix the Java method signatures (parse JSON strings to maps internally)
  2. 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'                                                                                          
    }                                                                                                                                 
} 

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions