Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with C++ Turbo Module in React Native 0.76.5 (Works in iOS, Not in Android) #48298

Open
cloud2303 opened this issue Dec 17, 2024 · 5 comments · May be fixed by #48340
Open

Issue with C++ Turbo Module in React Native 0.76.5 (Works in iOS, Not in Android) #48298

cloud2303 opened this issue Dec 17, 2024 · 5 comments · May be fixed by #48340
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: iOS iOS applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@cloud2303
Copy link

Description

I am using React Native 0.76.5, and I followed the steps to create a basic C++ Turbo Module demo. However, it does not work on Android, though it works fine on iOS. When I downgrade to React Native 0.76.1, the demo works on both iOS and Android.

Please advise on what might be causing this issue in 0.76.5.
I also came across this pull request, but even after switching to the latest version of OnLoad.cpp, the demo still doesn’t work on 0.76.5. My example repository is using 0.76.1, and I can reproduce the issue by switching to 0.76.5.

Steps to reproduce

  1. npm install

React Native Version

0.76.5

Affected Platforms

Runtime - Android

Areas

TurboModule - The New Native Module System

Output of npx react-native info

System:
  OS: Windows 11 10.0.22631
  CPU: (12) x64 12th Gen Intel(R) Core(TM) i5-12400
  Memory: 558.32 MB / 15.72 GB
Binaries:
  Node:
    version: 20.17.0
    path: C:\Program Files\nodejs\node.EXE
  Yarn: Not Found
  npm:
    version: 10.8.2
    path: C:\Program Files\nodejs\npm.CMD
  Watchman: Not Found
SDKs:
  Android SDK:
    API Levels:
      - "30"
      - "34"
      - "35"
    Build Tools:
      - 30.0.2
      - 34.0.0
      - 35.0.0
    System Images:
      - android-35 | Pre-Release 16 KB Page Size Google Play ARM Intel x86_64
        Atom
    Android NDK: Not Found
  Windows SDK:
    AllowDevelopmentWithoutDevLicense: Enabled
    AllowAllTrustedApps: Enabled
    Versions:
      - 10.0.19041.0
      - 10.0.20348.0
      - 10.0.22621.0
IDEs:
  Android Studio: Not Found
  Visual Studio:
    - 17.9.34701.34 (Visual Studio Professional 2022)
Languages:
  Java:
    version: 17.0.6
    path: /c/Users/fujiahui/.jdks/jbr-17.0.6/bin/javac
  Ruby: Not Found
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.1
    wanted: 15.0.1
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.1
    wanted: 0.76.1
  react-native-windows: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: Not found
  newArchEnabled: Not found

Stacktrace or Logs

dont load the custom cpp module

Reproducer

https://github.com/cloud2303/new-arch-cpp-module-test

Screenshots and Videos

No response

@cloud2303 cloud2303 added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Dec 17, 2024
@react-native-bot react-native-bot added Platform: Android Android applications. Platform: iOS iOS applications. labels Dec 17, 2024
@sarthak-d11
Copy link
Contributor

Hey @cloud2303
Would it be possible for you to share a reproducible example using React Native version 0.76.5? As the issue is occurring with this version, and having a sample would be very helpful for further investigation.

@cloud2303
Copy link
Author

Hi @sarthak-d11
I have adjusted the React Native version to 0.76.5, and you can find the updated repository at https://github.com/cloud2303/new-arch-cpp-module-test. This should provide a reproducible example of the issue.

@jankosecki
Copy link

jankosecki commented Dec 19, 2024

Getting the same issue - I've started by upgrading our app from 0.74 to 0.76.5 - once the app built but crashed due to:

Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeModule' could not be found.

I tried to simplify the app and I followed step-by-step guide which resulted in the same error anyway.

After finding this thread, I've downgraded RN to 0.76.1 in the sample app and my main app and both work fine on 0.76.1.

Upgrading to 0.76.2 breaks the app again so whatever causes the issue, must have been introduced in 0.76.2 release.

Edit:

I pinned it down to this commit 3956955. Using 0.76.5 but with previous version of ReactNative-application.cmake allows me to run the sample TurboModule app.

@cortinico - you are the author of the commit so you might be the best person to know how to fix the issue

@cipolleschi
Copy link
Contributor

I tried to investigate this a bit, and it looks like that, after the commit shared by @jankosecki, the OnLoad provided by the app is completely ignored by the app. I think we need to customize the CMakeLists.txt provided in the gradle.build

    externalNativeBuild {
        cmake {
            path "src/main/jni/CMakeLists.txt"
        }
    }

I tried something, like adding the OnLoad.cpp to the CMakeLists.txt file but we get duplicated symbols.

I don't have a lot more context here and I'm afraid we have to wait for Nicola to be back after PTO, he should be back next year.

@timbocole
Copy link

I’ve put together a potential fix: #48340

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs: Triage 🔍 Platform: Android Android applications. Platform: iOS iOS applications. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants