当我构建项目时出现错误,如下所示。我尝试了很多事情但从未成功。我使用的是 m1 MacBook。这与此错误有关吗?
[CXX1405]构建 Json 时出现异常启动进程“命令”/Users/serhat/Library/Android/sdk/cmake/3.18.1/bin/cmake”时出现问题
在 build.gradle 中:
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
这是 CmakeList.txt :
# For more information about using CMake with Android Studio,read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
src/main/cpp/native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
我解决了这个问题:
softwareupdate --install-rosetta
构建应用程序时出现 CMake 错误的解决方案可能是在 Mac 上安装 Rosetta。 Rosetta 是一种仿真技术,允许为 Intel 处理器设计的程序在配备 M1 或 M2 芯片的 Mac 上运行。有些程序,例如CMake,可能与M1或M2芯片本身不兼容,因此您需要安装Rosetta以确保这些程序正常工作。
要安装Rosetta,您可以使用以下命令:
softwareupdate --install-rosetta
安装 Rosetta 后,请尝试再次构建 React Native 应用程序。它应该可以正常工作,不会遇到您提到的错误。
我希望这个解决方案对您有所帮助。
我过去在使用 3.18.1 版本的 CMake 时也遇到过类似的问题。我建议从 Android Studio 中的 SDK Manager 重新安装 CMake SDK 工具。
如果重新运行后它似乎仍然引用 3.18.1,可能是因为模块在 build.gradle 文件中的某处直接引用它。
例如 我通过删除下面的代码在 expo-modules-core 中修复了这个问题,该代码似乎默认为旧版本的 CMake:
externalNativeBuild {
cmake {
if (REACT_NATIVE_TARGET_VERSION >= 71) {
path "CMakeLists.txt"
} else {
path "legacy/CMakeLists.txt"
}
}
}
我找到了解决此问题的简单解决方案。您所需要做的就是安装 Visual cplus cplus 重新分发文件。安装该依赖项后,一切都将开始完美运行。原因 Cpp 文件需要一些 cplus cplus 编译器 android studio 使用 inbuild microsoft cplus cplus 分发文件来实现此目的。
我还创建了一个视频指南来更详细地解释它: https://www.youtube.com/watch?v=Xg1wpeq0i_c
我也遇到这个问题
我发现我的window系统没有安装
Microsoft Visual C++
。
我安装了最新的vc运行库后就可以了。
您可以在此链接中找到该exe:https://learn.microsoft.com/en-us/cpp/windows/latest-supported-vc-redist?view=msvc-170#latest-microsoft-visual-c -可再发行版本