我创建了一个新的 React Native 项目 — Cli 并安装了这些 npm 包:
npm install @react-navigation/native
、npm install @react-navigation/stack
和 npm install @react-navigation/elements
。我的项目运行完美,但是当我安装 npm install react-native-gesture-handler
并使用 npx react-native run-android 运行我的项目时。
它显示错误,我尝试了,但错误没有解决。
Task :app:configureCMakeDebug[arm64-v8a] FAILED
Task :react-native-gesture-handler:compileDebugKotlin FAILED
Task :app:configureCMakeDebug[arm64-v8a]
C/C++: CMake Error at C:/Users/haide/Desktop/RN Test/AwesomeProject/android/app/build/generated/autolinking/src/main/jni/Android-autolinking.cmake:9 (add_subdirectory):
C/C++: add_subdirectory called with incorrect number of arguments
C/C++: Call Stack (most recent call first):
C/C++: C:/Users/haide/Desktop/RN Test/AwesomeProject/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:86 (include)
C/C++: CMakeLists.txt:31 (include)
C/C++: CMake Error at C:/Users/haide/Desktop/RN Test/AwesomeProject/node_modules/react-native/ReactAndroid/cmake-utils/ReactNative-application.cmake:89 (target_link_libraries):
C/C++: Cannot specify link libraries for target
C/C++: "react_codegen_rngesturehandler_codegen" which is not built by this
C/C++: project.
C/C++: Call Stack (most recent call first):
C/C++: CMakeLists.txt:31 (include)
> Task :app:configureCMakeDebug[arm64-v8a] FAILED
> Task :react-native-gesture-handler:compileDebugKotlin FAILED
我的项目的依赖项和版本。
"dependencies": {
"@react-navigation/elements": "^2.0.0",
"@react-navigation/native": "^7.0.0",
"@react-navigation/stack": "^7.0.0",
"react": "18.3.1",
"react-native": "0.76.1",
"react-native-gesture-handler": "^2.16.0"
},
您可以在 android/build.gradle 中更改
buildToolsVersion
和 buildToolsVersion
- 像这样:
// android/build.gradle
buildscript {
ext {
buildToolsVersion = 33
compileSdkVersion = 33
targetSdkVersion '33.0.0'
}
}