Skip to content

Commit e6374c6

Browse files
timbocolecipolleschi
authored andcommitted
fix: Prioritise local cpp (use default as fallback) (#48340)
Summary: #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 #48298 [ANDROID] [FIXED] - Prioritise local OnLoad.cpp, falling back to default-app-setup Pull Request resolved: #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 #47352 to ensure no regression Reviewed By: cipolleschi Differential Revision: D67736012 Pulled By: cortinico fbshipit-source-id: 87f6b8edf1613682585a94e1d1b3e6b4b792e4f5
1 parent 07b7953 commit e6374c6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,24 @@ set(BUILD_DIR ${PROJECT_BUILD_DIR})
3434
file(TO_CMAKE_PATH "${BUILD_DIR}" BUILD_DIR)
3535
file(TO_CMAKE_PATH "${REACT_ANDROID_DIR}" REACT_ANDROID_DIR)
3636

37-
file(GLOB input_SRC CONFIGURE_DEPENDS
38-
${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
39-
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
37+
if (PROJECT_ROOT_DIR)
38+
# This empty `if` is just to silence a CMake warning and make sure the `PROJECT_ROOT_DIR`
39+
# variable is defined if user need to access it.
40+
endif ()
41+
42+
file(GLOB override_cpp_SRC CONFIGURE_DEPENDS *.cpp)
43+
# We check if the user is providing a custom OnLoad.cpp file. If so, we pick that
44+
# for compilation. Otherwise we fallback to using the `default-app-setup/OnLoad.cpp`
45+
# file instead.
46+
if(override_cpp_SRC)
47+
file(GLOB input_SRC CONFIGURE_DEPENDS
48+
*.cpp
49+
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
50+
else()
51+
file(GLOB input_SRC CONFIGURE_DEPENDS
52+
${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp
53+
${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp)
54+
endif()
4055

4156
add_library(${CMAKE_PROJECT_NAME} SHARED ${input_SRC})
4257

0 commit comments

Comments
 (0)