react-native-community / cli

The React Native Community CLI - command line tools to help you build RN apps
MIT License
2.4k stars 905 forks source link

[Android] CMake Error at node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:89 (target_link_libraries): #2545

Closed bang9 closed 1 week ago

bang9 commented 1 week ago

Summary

Errors

Description

If libraryName exists in the build.gradle file on Android, it is identified as a new architecture library during the auto-linking process.

The findLibraryName function, which determines the config on Android, fetches libraryName simply through a regular expression. Therefore, even if this part is commented out, it will still be recognized.

As a result, even if it's an old architecture library, if libraryName is commented out as shown below, auto-linking will still attempt to treat it as a new architecture module. This leads to an attempt to link to a non-existent directory during the build process, ultimately causing the build to fail.

Logs

> com.android.ide.common.process.ProcessException: ninja: Entering directory `/Users/-/Desktop/bugs-repro/NACalls/android/app/.cxx/Debug/xf3y86r6/arm64-v8a'
  [0/2] Re-checking globbed directories...
  [1/2] Re-running CMake...
  -- Configuring incomplete, errors occurred!
  See also "/Users/-/Desktop/bugs-repro/NACalls/android/app/.cxx/Debug/xf3y86r6/arm64-v8a/CMakeFiles/CMakeOutput.log".
  FAILED: build.ninja 
  /Users/-/Library/Android/sdk/cmake/3.22.1/bin/cmake --regenerate-during-build -S/Users/-/Desktop/bugs-repro/NACalls/node_modules/react-native/ReactAndroid/cmake-utils/default-app-setup -B/Users/-/Desktop/bugs-repro/NACalls/android/app/.cxx/Debug/xf3y86r6/arm64-v8a

  C++ build system [build] failed while executing:
      /Users/-/Library/Android/sdk/cmake/3.22.1/bin/ninja \
        -C \
        /Users/-/Desktop/bugs-repro/NACalls/android/app/.cxx/Debug/xf3y86r6/arm64-v8a \
        appmodules
    from /Users/-/Desktop/bugs-repro/NACalls/android/app
  CMake Error at /Users/-/Desktop/bugs-repro/NACalls/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:9 (add_subdirectory):
    add_subdirectory given source
    "/Users/-/Desktop/bugs-repro/NACalls/node_modules/@sendbird/calls-react-native/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/-/Desktop/bugs-repro/NACalls/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:86 (include)
    CMakeLists.txt:31 (include)

  CMake Error at /Users/-/Desktop/bugs-repro/NACalls/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:89 (target_link_libraries):
    Cannot specify link libraries for target "react_codegen_rnsendbirdcalls"
    which is not built by this project.
  Call Stack (most recent call first):
    CMakeLists.txt:31 (include)

ninja: error: rebuilding 'build.ninja': subcommand failed
bang9 commented 1 week ago

There are quite a few functions that use regular expressions to extract configurations in Android, so adding comment-handling logic only to the findLibraryName function feels a bit odd. This issue seems to be more of an edge case, so handling it with an issue report should be sufficient.

If, despite using the old architecture, it doesn’t work in the interop layer and is recognized as a new architecture module, please check and remove the following:

  1. Remove the libraryName if it exists in the your-library/android/build.gradle file.
  2. Remove the codegenConfig field if it exists in the your-library/package.json file.