diff --git a/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake b/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake index 19dd6d632a131b..c29cfe392abb15 100644 --- a/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake +++ b/packages/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake @@ -39,9 +39,19 @@ if (PROJECT_ROOT_DIR) # variable is defined if user need to access it. endif () -file(GLOB input_SRC CONFIGURE_DEPENDS - ${REACT_ANDROID_DIR}/cmake-utils/default-app-setup/*.cpp - ${BUILD_DIR}/generated/autolinking/src/main/jni/*.cpp) +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})