react-native: [CXX1405] error when building with cmake

Description

Hi RN community,

I have an issue with ANDROID STUDIO when I try to build my app with new arch. Below is the error. Before I run:

./gradlew --stop
rm -rf ~/.gradle/caches/
[CXX1405] error when building with cmake using /Users/myuser/Projects/myproject/android/app/src/main/jni/CMakeLists.txt: Build command failed.
Error while executing process /Users/myuser/Library/Android/sdk/cmake/3.18.1/bin/cmake with arguments {-H/Users/myuser/Projects/myproject/android/app/src/main/jni -DCMAKE_SYSTEM_NAME=Android -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_SYSTEM_VERSION=24 -DANDROID_PLATFORM=android-24 -DANDROID_ABI=x86 -DCMAKE_ANDROID_ARCH_ABI=x86 -DANDROID_NDK=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529 -DCMAKE_ANDROID_NDK=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529 -DCMAKE_TOOLCHAIN_FILE=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=/Users/myuser/Library/Android/sdk/cmake/3.18.1/bin/ninja -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/myuser/Projects/myproject/android/app/build/intermediates/cxx/Debug/d144l2h3/obj/x86 -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/myuser/Projects/myproject/android/app/build/intermediates/cxx/Debug/d144l2h3/obj/x86 -DCMAKE_BUILD_TYPE=Debug -B/Users/myuser/Projects/myproject/android/app/.cxx/Debug/d144l2h3/x86 -GNinja -DPROJECT_BUILD_DIR=/Users/myuser/Projects/myproject/android/app/build -DREACT_ANDROID_DIR=/Users/myuser/Projects/myproject/android/../node_modules/react-native/ReactAndroid -DREACT_ANDROID_BUILD_DIR=/Users/myuser/Projects/myproject/android/../node_modules/react-native/ReactAndroid/build -DNODE_MODULES_DIR=/Users/myuser/Projects/myproject/android/../node_modules -DANDROID_STL=c++_shared}
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Users/myuser/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Users/myuser/Library/Android/sdk/ndk/21.4.7075529/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configuring done
-- Generating done

CMake Error in CMakeLists.txt:
  Imported target "fbjni" includes non-existent path

    "/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/src/main/jni/first-party/fbjni/headers"

CMake Error in CMakeLists.txt:
Imported target "fbjni" includes non-existent path

  in its INTERFACE_INCLUDE_DIRECTORIES.  Possible reasons include:

  * The path was deleted, renamed, or moved to another location.

  * An install or uninstall procedure did not complete successfully.

  * The installation package was faulty and references files it does not
  provide.



CMake Warning:
  Manually-specified variables were not used by the project:

    NODE_MODULES_DIR


CMake Generate step failed.  Build files cannot be regenerated correctly.

CMake Warning:
Manually-specified variables were not used by the project:

C/C++: prefabUsage: prefab [OPTIONS] PACKAGE_PATH...
C/C++: prefabError: Invalid value for "PACKAGE_PATH": Directory "/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab" is not readable.
[CXX1405] error when building with cmake using /Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/src/main/jni/CMakeLists.txt: Build command failed.
Error while executing java process with main class com.google.prefab.cli.AppKt with arguments {--build-system cmake --platform android --abi x86 --os-version 21 --stl c++_shared --ndk-version 21 --output /Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/.cxx/Debug/3q5b1z6p/prefab/x86/prefab-configure /Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab}

Usage: prefab [OPTIONS] PACKAGE_PATH...

Error: Invalid value for "PACKAGE_PATH": Directory "/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab" is not readable.

Invalid value for "PACKAGE_PATH": Directory "/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/prefab_package_configuration/debug/prefab" is not readable.

[CXX1400] Gradle project cmake.path is /Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes/CMakeLists.txt but that file doesn't exist
C/C++: debug|x86 :CMake Error: The source directory "/Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes" does not exist.
C/C++: debug|x86 :Specify --help for usage, or press the help button on the CMake GUI.
[CXX1405] error when building with cmake using /Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes/CMakeLists.txt: Build command failed.
Error while executing process /Users/myuser/Library/Android/sdk/cmake/3.18.1/bin/cmake with arguments {-H/Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes -DCMAKE_SYSTEM_NAME=Android -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_SYSTEM_VERSION=21 -DANDROID_PLATFORM=android-21 -DANDROID_ABI=x86 -DCMAKE_ANDROID_ARCH_ABI=x86 -DANDROID_NDK=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529 -DCMAKE_ANDROID_NDK=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529 -DCMAKE_TOOLCHAIN_FILE=/Users/myuser/Library/Android/sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=/Users/myuser/Library/Android/sdk/cmake/3.18.1/bin/ninja -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/cxx/Release/55n4523v/obj/x86 -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/intermediates/cxx/Release/55n4523v/obj/x86 -DCMAKE_FIND_ROOT_PATH=/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/.cxx/Release/55n4523v/prefab/x86/prefab -B/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/.cxx/Release/55n4523v/x86 -GNinja -DHERMES_IS_ANDROID=True -DANDROID_STL=c++_shared -DANDROID_PIE=True -DANDROID_LD=lld -DIMPORT_HERMESC=/Users/myuser/Projects/myproject/node_modules/react-native/ReactAndroid/hermes-engine/build/hermes/ImportHermesc.cmake -DJSI_DIR=/Users/myuser/Projects/myproject/node_modules/react-native/ReactCommon/jsi -DHERMES_SLOW_DEBUG=False -DHERMES_BUILD_SHARED_JSI=True -DHERMES_RELEASE_VERSION=for RN 0.70.2 -DHERMES_ENABLE_INTL=True -DCMAKE_BUILD_TYPE=Release}

CMake Error: The source directory "/Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

CMake Error: The source directory "/Users/myuser/Projects/myproject/node_modules/react-native/sdks/hermes" does not exist.
Specify --help for usage, or press the help button on the CMake GUI.

Version

0.70.2

Output of npx react-native info

System: OS: macOS 12.6 CPU: (12) x64 Intel® Core™ i7-9750H CPU @ 2.60GHz Memory: 353.41 MB / 16.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 18.6.0 - ~/.nvm/versions/node/v18.6.0/bin/node Yarn: 1.22.19 - ~/.yarn/bin/yarn npm: 8.19.2 - ~/.nvm/versions/node/v18.6.0/bin/npm Watchman: 2022.09.26.00 - /usr/local/bin/watchman Managers: CocoaPods: Not Found SDKs: iOS SDK: Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0 Android SDK: API Levels: 29, 30, 31 Build Tools: 29.0.2, 30.0.2, 30.0.3, 31.0.0 System Images: android-30 | Google APIs Intel x86 Atom, android-30 | Google Play Intel x86 Atom, android-31 | Google APIs Intel x86 Atom_64, android-31 | Google Play Intel x86 Atom_64 Android NDK: 22.1.7171670 IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8512546 Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild Languages: Java: javac 19 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 18.1.0 => 18.1.0 react-native: 0.70.2 => 0.70.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Steps to reproduce

Android Studio > Build > Clean Project Android Studio > Build > Refresh Linked C++ Project ( I have an issue CMake Error in CMakeLists.txt: Imported target “fbjni” includes non-existent path)

Android Studio > Build > Build Project > [CXX1405] error when building with cmake

Snack, code example, screenshot, or link to a repository

android/gradle.properties

# Project-wide Gradle settings.

# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.

# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html

# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx512m -XX:MaxMetaspaceSize=256m
org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true

# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
android.enableJetifier=true

# Version of flipper SDK to use with React Native
FLIPPER_VERSION=0.164.0

# Use this property to specify which architecture you want to build.
# You can also override it from the CLI using
# ./gradlew <task> -PreactNativeArchitectures=x86_64
reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64

# Use this property to enable support to the new architecture.
# This will allow you to use TurboModules and the Fabric render in
# your application. You should enable this flag either if you want
# to write custom TurboModules/Fabric components OR use libraries that
# are providing them.
newArchEnabled=true

disableMultipleInstancesCheck=true

android/app/proguard-rules.pro

# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
#   http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:
-keep class com.facebook.hermes.unicode.** { *; }
-keep class com.facebook.jni.** { *; }

android/app/src/main/jni/CMakeLists.txt

cmake_minimum_required(VERSION 3.13)

# Define the library name here.
project(myproject_appmodules)

# This file includes all the necessary to let you build your application with the New Architecture.
include(${REACT_ANDROID_DIR}/cmake-utils/ReactNative-application.cmake)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 11
  • Comments: 36 (7 by maintainers)

Most upvoted comments

I’m closing as @alfredarcifa is unresponsive. This and other build failures for New Architecture in 0.70 have been fixed in 0.71

If you’re still seeing similar issues like this one (e.g. as @Dat-Mobile mentioned), open a new issue and provide a reproducer.

Hi @cortinico , I got same issue in 70.3. Any fix for this? as bumping the com.android.tools.build:gradle didn’t worked for me

I just removed .cxx folder in ./android/app/. I worked but I don’t know the reason. (I just think removing the cache file is the only way.) Can anybody explain this?

If doesn’t work, remove ./android/app/build folder too

Fixed with updating com.android.tools.build:gradle from 7.2.2 to 7.3.0

🤷

@cortinico @alfredarcifa

I had the same issue on Windows 10. Fixed by uninstalling the cmake from the system path.

this works for me

windows 11

hey how did you find the cmake system path?

For windows. You need to install the c++runtime.This works for me. Dingtalk_20230105094928

I just cleared all the cache,

path on windows: C:\Users\xxx.gradle\

hey , tried with that too but still getting this > [CXX1428] exception while building Json A problem occurred starting process ‘command ‘C:\Users\hp\AppData\Local\Android\Sdk\cmake\3.22.1\bin\cmake.exe’’ , any other way? to get resolved from this

You must only install C++ sdk to your pc.

For x64: here For x86: here

and do the following processes respectively:

  • delete node_modules directory.
  • delete android/build directory.
  • delete android/.gradle directory.
  • delete android/app/build directory then
  • run “yarn” command.
  • run “yarn ios” or “yarn android” command. ( run the project. )

I had the same issue on Windows 10. Fixed by uninstalling the cmake from the system path.

How did you do this?

I had the same issue on Windows 10. Fixed by uninstalling the cmake from the system path.

Fixed with updating com.android.tools.build:gradle from 7.2.2 to 7.3.0

🤷

@cortinico @alfredarcifa

Are you sure? If I set 7.3.0 in build.gradle I receive an error console:

A problem occurred evaluating project ':app'.
> Failed to apply plugin 'com.android.internal.version-check'.
   > Minimum supported Gradle version is 7.4. Current version is 7.3.3. If using the gradle wrapper, try editing the distributionUrl in /Users/user/Projects/project/android/gradle/wrapper/gradle-wrapper.properties to gradle-7.4-all.zip