Skip to content

[0.76] Project with custom C++ code - Crashes with EarlyJsError: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary #47352

@auliakbarh

Description

@auliakbarh

Description

I'm using "react-native": "0.76.0", and I tried to implement ndk but I got an error:

EarlyJsError: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary

image

I need to secure my env since in react-native-config mentioned
Keep in mind this module doesn't obfuscate or encrypt secrets for packaging, so do not store sensitive keys in .env

in android/app/build.gradle:

android {
  ...
  externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
            version '3.22.1'
        }
    }
  ...
}

That lines causing the error, but when I remove those lines I can't use the secrets.

can anyone help me?

Steps to reproduce

Try to implement these:

React Native Version

0.76.0

Affected Platforms

Runtime - Android

Areas

TurboModule - The New Native Module System

Output of npx react-native info

System:
  OS: macOS 15.1
  CPU: (10) arm64 Apple M2 Pro
  Memory: 125.73 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.16.0
    path: ~/.nvm/versions/node/v20.16.0/bin/node
  Yarn:
    version: 1.22.21
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.1
    path: ~/.nvm/versions/node/v20.16.0/bin/npm
  Watchman:
    version: 2024.10.28.00
    path: /usr/local/bin/watchman
Managers:
  CocoaPods:
    version: 1.15.2
    path: /Users/auliakbarh/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.1
      - iOS 18.1
      - macOS 15.1
      - tvOS 18.1
      - visionOS 2.1
      - watchOS 11.1
  Android SDK:
    API Levels:
      - "33"
      - "34"
      - "35"
    Build Tools:
      - 30.0.3
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
      - 35.0.0
    System Images:
      - android-34 | Google APIs ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2024.2 AI-242.23339.11.2421.12550806
  Xcode:
    version: 16.1/16B40
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.9
    path: /usr/bin/javac
  Ruby:
    version: 2.7.4
    path: /Users/auliakbarh/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 15.0.0-alpha.2
    wanted: 15.0.0-alpha.2
  react:
    installed: 18.3.1
    wanted: 18.3.1
  react-native:
    installed: 0.76.0
    wanted: 0.76.0
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

Exception in native call from JS
                                                                                                    com.facebook.react.common.JavascriptException: EarlyJsError: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary., stack:
                                                                                                    invariant@2040:26
                                                                                                    getEnforcing@2665:28
                                                                                                    anonymous@356569:68
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@356545:76
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@356504:75
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@22336:53
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@25358:51
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@25344:200
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@175:38
                                                                                                    metroRequire@89:92
                                                                                                    anonymous@20594:14
                                                                                                    loadModuleImplementation@267:14
                                                                                                    guardedLoadModule@168:47
                                                                                                    metroRequire@89:92
                                                                                                    global@359111:4
                                                                                                    
                                                                                                    	at com.facebook.react.modules.core.ExceptionsManagerModule.reportException(ExceptionsManagerModule.kt:52)
                                                                                                    	at com.facebook.react.runtime.ReactInstance$ReactJsExceptionHandlerImpl.reportJsException(ReactInstance.java:336)
                                                                                                    	at com.facebook.jni.NativeRunnable.run(Native Method)
                                                                                                    	at android.os.Handler.handleCallback(Handler.java:959)
                                                                                                    	at android.os.Handler.dispatchMessage(Handler.java:100)
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:27)
                                                                                                    	at android.os.Looper.loopOnce(Looper.java:232)
                                                                                                    	at android.os.Looper.loop(Looper.java:317)
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2(MessageQueueThreadImpl.java:217)
                                                                                                    	at com.facebook.react.bridge.queue.MessageQueueThreadImpl$$ExternalSyntheticLambda1.run(D8$$SyntheticClass:0)
                                                                                                    	at java.lang.Thread.run(Thread.java:1012)

Reproducer

https://github.com/auliakbarh/reproduce-error-turbomodule-rn-using-cmake

Screenshots and Videos

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Resolution: PR SubmittedA pull request with a fix has been provided.Type: New ArchitectureIssues and PRs related to new architecture (Fabric/Turbo Modules)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions