Skip to content

[Android] GenerateAutolinkingNewArchitecturesFileTask still emits invalid add_subdirectory entries on 0.83.1 when JNI codegen dirs are missing #56334

@sagnik2001

Description

@sagnik2001

Description

Description

This still reproduces for me on React Native 0.83.1 with New Architecture enabled.

The generated Android-autolinking.cmake contains unconditional
add_subdirectory(...) entries for JNI/codegen directories under dependencies, e.g.

node_modules/<package>/android/build/generated/source/codegen/jni/

During ./gradlew clean, some of those directories do not exist, and CMake fails with:

add_subdirectory given source ".../jni/" which is not an existing directory

This prevents clean/build from completing.

A local fix is to update
GenerateAutolinkingNewArchitecturesFileTask.kt
so generated CMake:

  • wraps add_subdirectory(...) with if(EXISTS ...)
  • only appends the library to AUTOLINKED_LIBRARIES if that directory was actually added

Steps to reproduce

  1. Enable New Architecture
  2. Install dependencies
  3. Run ./gradlew clean
  4. Observe failure in generated Android-autolinking.cmake

React Native Version

0.83.1

Affected Platforms

Build - MacOS, Runtime - Android

Areas

Codegen, Other (please specify), TurboModule - The New Native Module System

Output of npx @react-native-community/cli info

info Fetching system and libraries information...
System:
  OS: macOS 26.2
  CPU: (10) arm64 Apple M4
  Memory: 301.59 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 20.19.4
    path: /Users/admin/.nvm/versions/node/v20.19.4/bin/node
  Yarn: Not Found
  npm:
    version: 10.8.2
    path: /Users/admin/.nvm/versions/node/v20.19.4/bin/npm
  Watchman:
    version: 2025.06.30.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/admin/.rvm/gems/ruby-3.1.0/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.4
      - iOS 26.4
      - macOS 26.4
      - tvOS 26.4
      - visionOS 26.4
      - watchOS 26.4
  Android SDK:
    API Levels:
      - "28"
      - "33"
      - "34"
      - "35"
      - "36"
    Build Tools:
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 36.0.0
    System Images:
      - android-33 | Google APIs ARM 64 v8a
      - android-34 | Google APIs ARM 64 v8a
      - android-34 | Google Play 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: 26.4/17E192
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.13
    path: /usr/bin/javac
  Ruby:
    version: 3.1.0
    path: /Users/admin/.rvm/rubies/ruby-3.1.0/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.2.0
    wanted: 19.2.0
  react-native:
    installed: 0.83.1
    wanted: 0.83.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

> Task :app:externalNativeBuildCleanDebug FAILED
Clean react_codegen_rnreanimated-arm64-v8a, react_codegen_safeareacontext-arm64-v8a, appmodules-arm64-v8a, react_codegen_rnworklets-arm64-v8a
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:9 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@d11/react-native-fast-image/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:10 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@react-native-clipboard/clipboard/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:11 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@react-native-community/netinfo/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:12 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-config/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:13 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-gesture-handler/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:14 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-nitro-modules/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:15 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-permissions/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:16 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-reanimated/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:18 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-share/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:19 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-webview/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:20 (add_subdirectory):
C/C++:   add_subdirectory given source
C/C++:   "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-worklets/android/build/generated/source/codegen/jni/"
C/C++:   which is not an existing directory.
C/C++: Call Stack (most recent call first):
C/C++:   /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
C/C++:   CMakeLists.txt:31 (include)
C/C++: CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:97 (target_link_libraries):
C/C++:   Cannot specify link libraries for target "react_codegen_RNFastImageSpec"
C/C++:   which is not built by this project.
C/C++: Call Stack (most recent call first):
C/C++:   CMakeLists.txt:31 (include)
C/C++: ninja: error: rebuilding 'build.ninja': subcommand failed

[Incubating] Problems report is available at: file:///Users/admin/Downloads/React-native-gradle-plugin-test/android/build/reports/problems/problems-report.html

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:externalNativeBuildCleanDebug'.
> com.android.ide.common.process.ProcessException: ninja: Entering directory `/Users/admin/Downloads/React-native-gradle-plugin-test/android/app/.cxx/Debug/2l3a356k/arm64-v8a'
  [0/2] Re-checking globbed directories...
  [1/2] Re-running CMake...
  -- Configuring incomplete, errors occurred!
  See also "/Users/admin/Downloads/React-native-gradle-plugin-test/android/app/.cxx/Debug/2l3a356k/arm64-v8a/CMakeFiles/CMakeOutput.log".
  See also "/Users/admin/Downloads/React-native-gradle-plugin-test/android/app/.cxx/Debug/2l3a356k/arm64-v8a/CMakeFiles/CMakeError.log".
  FAILED: build.ninja 
  /Users/admin/Library/Android/sdk/cmake/3.22.1/bin/cmake --regenerate-during-build -S/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/default-app-setup -B/Users/admin/Downloads/React-native-gradle-plugin-test/android/app/.cxx/Debug/2l3a356k/arm64-v8a
  
  C++ build system [clean] failed while executing:
      /Users/admin/Library/Android/sdk/cmake/3.22.1/bin/ninja \
        -C \
        /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/.cxx/Debug/2l3a356k/arm64-v8a \
        clean
    from /Users/admin/Downloads/React-native-gradle-plugin-test/android/app
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:9 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@d11/react-native-fast-image/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:10 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@react-native-clipboard/clipboard/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:11 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/@react-native-community/netinfo/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:12 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-config/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:13 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-gesture-handler/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:14 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-nitro-modules/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:15 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-permissions/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:16 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-reanimated/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:18 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-share/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:19 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-webview/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:20 (add_subdirectory):
    add_subdirectory given source
    "/Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native-worklets/android/build/generated/source/codegen/jni/"
    which is not an existing directory.
  Call Stack (most recent call first):
    /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:94 (include)
    CMakeLists.txt:31 (include)
  
  
  CMake Error at /Users/admin/Downloads/React-native-gradle-plugin-test/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:97 (target_link_libraries):
    Cannot specify link libraries for target "react_codegen_RNFastImageSpec"
    which is not built by this project.
  Call Stack (most recent call first):
    CMakeLists.txt:31 (include)
  
  
  ninja: error: rebuilding 'build.ninja': subcommand failed

* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to generate a Build Scan (Powered by Develocity).
> Get more help at https://help.gradle.org.

Deprecated Gradle features were used in this build, making it incompatible with Gradle 10.

You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.

For more on this, please refer to https://docs.gradle.org/9.0.0/userguide/command_line_interface.html#sec:command_line_warnings in the Gradle documentation.

BUILD FAILED in 4s

MANDATORY Reproducer

https://github.com/Sagniknewme09/React-native-gradle-plugin-test

Public reproducer repo:
https://github.com/Sagniknewme09/React-native-gradle-plugin-test

Repro steps:

  1. npm install
  2. cd android
  3. ./gradlew clean

Observed:
Generated Android-autolinking.cmake contains unconditional add_subdirectory(...) entries for missing build/generated/source/codegen/jni directories, and clean fails.

Expected:
./gradlew clean should succeed even when those generated JNI directories do not exist yet.

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    API: LinkingNeeds: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.Platform: AndroidAndroid applications.Type: New ArchitectureIssues and PRs related to new architecture (Fabric/Turbo Modules)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions