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

[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

Closed
auliakbarh opened this issue Nov 1, 2024 · 13 comments
Labels
Resolution: PR Submitted A pull request with a fix has been provided. Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules)

Comments

@auliakbarh
Copy link

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

@auliakbarh auliakbarh added Needs: Triage 🔍 Type: New Architecture Issues and PRs related to new architecture (Fabric/Turbo Modules) labels Nov 1, 2024
@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - 0.76.1. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@react-native-bot
Copy link
Collaborator

⚠️ Newer Version of React Native is Available!
ℹ️ You are on a supported minor version, but it looks like there's a newer patch available - undefined. Please upgrade to the highest patch for your minor or latest and verify if the issue persists (alternatively, create a new project and repro the issue in it). If it does not repro, please let us know so we can close out this issue. This helps us ensure we are looking at issues that still exist in the most recent releases.

@goguda goguda mentioned this issue Nov 1, 2024
@goguda
Copy link

goguda commented Nov 1, 2024

We're getting this too since upgrading to 0.76 in production on specific phones, mostly Android 14. Haven't been able to reproduce in development:

Thread terminating due to uncaught exception of type facebook::jni::JniException: 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:

*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
pid: 0, tid: 11864 >>> com.iroomit.iroomitapp <<<

backtrace:
  #00  pc 0x00000000000927e8  /apex/com.android.runtime/lib64/bionic/libc.so (abort+164)
  #01  pc 0x000000000009dd84  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: 982d68842b3bd6a164609be09a533324b1f28526)
  #02  pc 0x000000000009ca44  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: 982d68842b3bd6a164609be09a533324b1f28526)
  #03  pc 0x000000000009ced4  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libc++_shared.so (BuildId: 982d68842b3bd6a164609be09a533324b1f28526)
  #04  pc 0x000000000009ce74  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libc++_shared.so (std::terminate()+56) (BuildId: 982d68842b3bd6a164609be09a533324b1f28526)
  #05  pc 0x0000000000345624  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #06  pc 0x0000000000540408  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #07  pc 0x000000000039af84  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (facebook::react::JsErrorHandler::handleFatalError(facebook::jsi::Runtime&, facebook::jsi::JSError&)+5544) (BuildId: 1418e94c42deb385)
  #08  pc 0x0000000000350114  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #09  pc 0x00000000000bb7f0  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #10  pc 0x00000000000bb450  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #11  pc 0x00000000000c2528  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #12  pc 0x00000000000d2874  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #13  pc 0x00000000000d4224  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #14  pc 0x00000000000d38e0  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #15  pc 0x0000000000106cb4  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #16  pc 0x00000000000ae924  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #17  pc 0x00000000000ae7ac  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (facebook::hermes::HermesRuntime::evaluateJavaScriptWithSourceMap(std::__ndk1::shared_ptr<facebook::jsi::Buffer const> const&, std::__ndk1::shared_ptr<facebook::jsi::Buffer const> const&, std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char> > const&)+100) (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #18  pc 0x00000000000af7c8  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libhermes.so (BuildId: b0f589a6e8d91abac4ce7ed08803646a812a4f49)
  #19  pc 0x000000000034c224  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #20  pc 0x00000000004dc138  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #21  pc 0x0000000000349e28  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #22  pc 0x000000000051b7b4  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libreactnative.so (BuildId: 1418e94c42deb385)
  #23  pc 0x0000000000019804  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libfbjni.so (facebook::jni::detail::MethodWrapper<void (facebook::jni::JNativeRunnable::*)(), &(facebook::jni::JNativeRunnable::run()), facebook::jni::JNativeRunnable, void>::dispatch(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::jni::JNativeRunnable, facebook::jni::JRunnable>::JavaPart, facebook::jni::JRunnable, void>::_javaobject*>)+72) (BuildId: a22242831a7971267de570e06121acb588ce64cd)
  #24  pc 0x0000000000019744  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/split_config.arm64_v8a.apk!libfbjni.so (facebook::jni::detail::FunctionWrapper<void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::jni::JNativeRunnable, facebook::jni::JRunnable>::JavaPart, facebook::jni::JRunnable, void>::_javaobject*>), facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::jni::JNativeRunnable, facebook::jni::JRunnable>::JavaPart, facebook::jni::JRunnable, void>::_javaobject*, void>::call(_JNIEnv*, _jobject*, void (*)(facebook::jni::alias_ref<facebook::jni::detail::JTypeFor<facebook::jni::HybridClass<facebook::jni::JNativeRunnable, facebook::jni::JRunnable>::JavaPart, facebook::jni::JRunnable, void>::_javaobject*>))+60) (BuildId: a22242831a7971267de570e06121acb588ce64cd)
  #25  pc 0x00000000003343c0  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (art_jni_trampoline+112)
  #26  pc 0x0000000000971514  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Handler.dispatchMessage+68)
  #27  pc 0x000000000077f820  /apex/com.android.art/lib64/libart.so (nterp_helper+4016)
  #28  pc 0x000000000024c1fc  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/base.apk (com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage)
  #29  pc 0x0000000000974ed4  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loopOnce+980)
  #30  pc 0x0000000000974a64  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (android.os.Looper.loop+916)
  #31  pc 0x000000000077e908  /apex/com.android.art/lib64/libart.so (nterp_helper+152)
  #32  pc 0x000000000024c722  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/base.apk (com.facebook.react.bridge.queue.MessageQueueThreadImpl.lambda$startNewBackgroundThread$2+70)
  #33  pc 0x000000000077e908  /apex/com.android.art/lib64/libart.so (nterp_helper+152)
  #34  pc 0x000000000024c528  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/base.apk (com.facebook.react.bridge.queue.MessageQueueThreadImpl.b)
  #35  pc 0x000000000077e908  /apex/com.android.art/lib64/libart.so (nterp_helper+152)
  #36  pc 0x00000000002ece40  /data/app/~~Ma_iqwSnCAWnGFXBm5aSeg==/com.iroomit.iroomitapp-6tfaOSi7OQ5KBpu0nbNxjw==/base.apk (com.microsoft.clarity.I5.b.run+4)
  #37  pc 0x000000000040f510  /data/misc/apexdata/com.android.art/dalvik-cache/arm64/boot.oat (java.lang.Thread.run+64)
  #38  pc 0x0000000000362774  /apex/com.android.art/lib64/libart.so (art_quick_invoke_stub+612)
  #39  pc 0x000000000034def0  /apex/com.android.art/lib64/libart.so (art::ArtMethod::Invoke(art::Thread*, unsigned int*, unsigned int, art::JValue*, char const*)+132)
  #40  pc 0x0000000000943e28  /apex/com.android.art/lib64/libart.so (art::detail::ShortyTraits<(char)86>::Type art::ArtMethod::InvokeInstance<(char)86>(art::Thread*, art::ObjPtr<art::mirror::Object>, art::detail::ShortyTraits<>::Type...)+60)
  #41  pc 0x000000000063ebd4  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallback(void*)+1344)
  #42  pc 0x000000000063e684  /apex/com.android.art/lib64/libart.so (art::Thread::CreateCallbackWithUffdGc(void*)+8)
  #43  pc 0x00000000000f74f8  /apex/com.android.runtime/lib64/bionic/libc.so (__pthread_start(void*)+208)
  #44  pc 0x0000000000094020  /apex/com.android.runtime/lib64/bionic/libc.so (__start_thread+64)

New architecture is disabled for us.

@cortinico cortinico changed the title EarlyJsError: TurboModuleRegistry.getEnforcing(...): 'PlatformConstants' could not be found. Verify that a module by this name is registered in the native binary [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 Nov 4, 2024
@cortinico
Copy link
Contributor

Sort of a duplicate of: #38467

However for your specific scenario we would need a fix inside core:

Moreover you will have to update your CMakeLists.txt file as follows:

cmake_minimum_required(VERSION 3.22.1)

project(appmodules)

# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

add_library(secrets STATIC src/main/cpp/secrets.cpp)
target_link_libraries(secrets android log)
target_link_libraries(${CMAKE_PROJECT_NAME}
    secrets)

That's because you're providing your own CMake file and not the app default.
This behavior is explained here:

# This CMake file is the default used by apps and is placed inside react-native
# to encapsulate it from user space (so you won't need to touch C++/Cmake code at all on Android).
#
# If you wish to customize it (because you want to manually link a C++ library or pass a custom
# compilation flag) you can:
#
# 1. Copy this CMake file inside the `android/app/src/main/jni` folder of your project
# 2. Copy the OnLoad.cpp (in this same folder) file inside the same folder as above.
# 3. Extend your `android/app/build.gradle` as follows
#
# android {
# // Other config here...
# externalNativeBuild {
# cmake {
# path "src/main/jni/CMakeLists.txt"
# }
# }
# }

@cortinico cortinico added Resolution: PR Submitted A pull request with a fix has been provided. and removed Needs: Triage 🔍 labels Nov 4, 2024
@goguda
Copy link

goguda commented Nov 4, 2024

Sort of a duplicate of: #38467

However for your specific scenario we would need a fix inside core:

* [Use absolute path when compiling appmodules.so sources #47379](https://github.com/facebook/react-native/pull/47379)

Moreover you will have to update your CMakeLists.txt file as follows:

cmake_minimum_required(VERSION 3.22.1)

project(appmodules)

# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

add_library(secrets STATIC src/main/cpp/secrets.cpp)
target_link_libraries(secrets android log)
target_link_libraries(${CMAKE_PROJECT_NAME}
    secrets)

That's because you're providing your own CMake file and not the app default. This behavior is explained here:

# This CMake file is the default used by apps and is placed inside react-native
# to encapsulate it from user space (so you won't need to touch C++/Cmake code at all on Android).
#
# If you wish to customize it (because you want to manually link a C++ library or pass a custom
# compilation flag) you can:
#
# 1. Copy this CMake file inside the `android/app/src/main/jni` folder of your project
# 2. Copy the OnLoad.cpp (in this same folder) file inside the same folder as above.
# 3. Extend your `android/app/build.gradle` as follows
#
# android {
# // Other config here...
# externalNativeBuild {
# cmake {
# path "src/main/jni/CMakeLists.txt"
# }
# }
# }

It might be the case for auliakbarh, but the weird this is we're not using any custom C++ or CMakeLists.txt in our project.

I did a search through our project, and the only time I can see PlatformConstants attempting to be accessed is in react-native-gesture-handler. Perhaps that package needs to implement this fix?

@cortinico
Copy link
Contributor

It might be the case for auliakbarh, but the weird this is we're not using any custom C++ or CMakeLists.txt in our project.

Please don't hijack this issue.

Open another issue and provide a separate reproducer as otherwise is extremely complicated for us to help everyone.

@auliakbarh
Copy link
Author

Sort of a duplicate of: #38467

However for your specific scenario we would need a fix inside core:

Moreover you will have to update your CMakeLists.txt file as follows:

cmake_minimum_required(VERSION 3.22.1)

project(appmodules)

# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

add_library(secrets STATIC src/main/cpp/secrets.cpp)
target_link_libraries(secrets android log)
target_link_libraries(${CMAKE_PROJECT_NAME}
    secrets)

That's because you're providing your own CMake file and not the app default. This behavior is explained here:

# This CMake file is the default used by apps and is placed inside react-native
# to encapsulate it from user space (so you won't need to touch C++/Cmake code at all on Android).
#
# If you wish to customize it (because you want to manually link a C++ library or pass a custom
# compilation flag) you can:
#
# 1. Copy this CMake file inside the `android/app/src/main/jni` folder of your project
# 2. Copy the OnLoad.cpp (in this same folder) file inside the same folder as above.
# 3. Extend your `android/app/build.gradle` as follows
#
# android {
# // Other config here...
# externalNativeBuild {
# cmake {
# path "src/main/jni/CMakeLists.txt"
# }
# }
# }

I tried to update my CMakeLists.txt as your mentioned, but still got the same error. Is it need to wait for the core section to be fixed first?

@cortinico
Copy link
Contributor

Is it need to wait for the core section to be fixed first?

Correct

blakef pushed a commit that referenced this issue Nov 12, 2024
Summary:
Fixes #47352

This fixes a bug when the user is providing its own CMakeLists.txt file say because they want to compile more C++ code than we actually provide.

Previously the `*.cpp` will evalute file in the current directory, meaning that the app's default `OnLoad.cpp` file would be ignored.

## Changelog:

[ANDROID] [FIXED] - Use absolute path when compiling appmodules.so sources

Pull Request resolved: #47379

Test Plan:
Tested against the reproducer provided in:
- Use absolute path when compiling appmodules.so sources

Reviewed By: cipolleschi

Differential Revision: D65428676

Pulled By: cortinico

fbshipit-source-id: 7f3e4d470da0fffc5191c1a2c7e8fec517fee496
@jerinjohnk
Copy link

jerinjohnk commented Nov 14, 2024

Created an Android Release variant app using old architecture and triggered a firebase notification in the app Killed state.
The same error can be seen in the Android logcat.

diff --git a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
index 451a066..805ef11 100644
--- a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
+++ b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
@@ -36,7 +36,7 @@ if(CMAKE_HOST_WIN32)
 endif()
 
 file(GLOB input_SRC CONFIGURE_DEPENDS
-        *.cpp
+        ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
         ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
 
 add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

The notification works fine in the background and foreground state.
The third-party (moengage) we use for notification works fine in all three states.

@nes123
Copy link

nes123 commented Nov 14, 2024

Created an Android Release variant app using old architecture and triggered a firebase notification in the app Killed state. The same error can be seen in the Android logcat.

diff --git a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
index 451a066..805ef11 100644
--- a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
+++ b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
@@ -36,7 +36,7 @@ if(CMAKE_HOST_WIN32)
 endif()
 
 file(GLOB input_SRC CONFIGURE_DEPENDS
-        *.cpp
+        ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
         ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
 
 add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

The notification works fine in the background and foreground state. The third-party (moengage) we use for notification works fine in all three states.

is the absolute path fixing the problem for you?

@jerinjohnk
Copy link

jerinjohnk commented Nov 14, 2024

No, it's not fixing. The error occurs when a Firebase notification is triggered to the release variant apk in its killed state. It can be viewed in the Android logcat.

@nes123
Copy link

nes123 commented Nov 14, 2024

Created an Android Release variant app using old architecture and triggered a firebase notification in the app Killed state. The same error can be seen in the Android logcat.

diff --git a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
index 451a066..805ef11 100644
--- a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
+++ b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
@@ -36,7 +36,7 @@ if(CMAKE_HOST_WIN32)
 endif()
 
 file(GLOB input_SRC CONFIGURE_DEPENDS
-        *.cpp
+        ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
         ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
 
 add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

The notification works fine in the background and foreground state. The third-party (moengage) we use for notification works fine in all three states.

is the absolute path fixing the problem for you?

No, it's not fixing. The error still occurs when a Firebase notification is triggered to the release variant apk in its killed state. It can be viewed in the Android logcat.

same problem here..i managed to reproduce it.

@jerinjohnk
Copy link

Created an Android Release variant app using old architecture and triggered a firebase notification in the app Killed state. The same error can be seen in the Android logcat.

diff --git a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
index 451a066..805ef11 100644
--- a/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
+++ b/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake
@@ -36,7 +36,7 @@ if(CMAKE_HOST_WIN32)
 endif()
 
 file(GLOB input_SRC CONFIGURE_DEPENDS
-        *.cpp
+        ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
         ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
 
 add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})

The notification works fine in the background and foreground state. The third-party (moengage) we use for notification works fine in all three states.

The error generated in this case is as follows.

terminating due to uncaught exception of type facebook::jni::JniException:
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@1:169639
  getEnforcing@1:176737
  anonymous@1:176277
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
  anonymous@1:175270
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
   anonymous@1:174886
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
  anonymous@1:181098
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
  anonymous@1:179937
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
  anonymous@1:378744
  loadModuleImplementation@1:139594
  guardedLoadModule@1:139117
  metroRequire@1:138747
  anonymous@1:377674
  loadModuleImplementation@1:139594
  guardedLoadModule@1:1391

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: PR Submitted A pull request with a fix has been provided. 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