From e6374c6e601429992db3e67d88cf083e46c58f5b Mon Sep 17 00:00:00 2001 From: timbocole Date: Tue, 31 Dec 2024 05:30:26 -0800 Subject: [PATCH] fix: Prioritise local cpp (use default as fallback) (#48340) Summary: https://github.com/facebook/react-native/pull/47379 removed local cpp sources from the sources being built with the app. This resulted in a local `android/app/src/main/jni/OnLoad.cpp` file being ignored at build time. I have therefore added logic to the cmake file to prioritise local `cpp` files and fallback to `${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp` if none exist. This resolves https://github.com/facebook/react-native/issues/48298 [ANDROID] [FIXED] - Prioritise local OnLoad.cpp, falling back to default-app-setup Pull Request resolved: https://github.com/facebook/react-native/pull/48340 Test Plan: - Followed the https://reactnative.dev/docs/the-new-architecture/pure-cxx-modules guide (which was broken > 0.76.1) - Applied the patch to the reproduction repository linked to https://github.com/facebook/react-native/issues/47352 to ensure no regression Reviewed By: cipolleschi Differential Revision: D67736012 Pulled By: cortinico fbshipit-source-id: 87f6b8edf1613682585a94e1d1b3e6b4b792e4f5 --- .../cmake-utils/ReactNative-application.cmake | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake index 691fc465922139..05cb5a97bf3f99 100644 --- a/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake +++ b/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake @@ -34,9 +34,24 @@ set(BUILD_DIR ${PROJECT_BUILD_DIR}) file(TO_CMAKE_PATH "${BUILD_DIR}" BUILD_DIR) file(TO_CMAKE_PATH "${REACT_ANDROID_DIR}" REACT_ANDROID_DIR) -file(GLOB input_SRC CONFIGURE_DEPENDS - ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp - ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp) +if (PROJECT_ROOT_DIR) +# This empty `if` is just to silence a CMake warning and make sure the `PROJECT_ROOT_DIR` +# variable is defined if user need to access it. +endif () + +file(GLOB override_cpp_SRC CONFIGURE_DEPENDS *.cpp) +# We check if the user is providing a custom OnLoad.cpp file. If so, we pick that +# for compilation. Otherwise we fallback to using the `default-app-setup/OnLoad.cpp` +# file instead. +if(override_cpp_SRC) + file(GLOB input_SRC CONFIGURE_DEPENDS + *.cpp + ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp) +else() + file(GLOB input_SRC CONFIGURE_DEPENDS + ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp + ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp) +endif() add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})