当我构建ndk app时,会出现错误:
Error:(21, 10) fatal error: 'asm/types.h' file not found
我找到了类似问题的答案,这些答案增加了CMakeLists.txt
if(${ANDROID_ABI} STREQUAL "armeabi-v7a")
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
elseif(${ANDROID_ABI} STREQUAL "arm64-v8a")
include_directories(${ANDROID_SYSROOT}/usr/include/aarch64-linux-android)
else()
include_directories(${ANDROID_SYSROOT}/usr/include/arm-linux-androideabi)
endif()
但是发生了另一个错误:
Error:FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:externalNativeBuildDebug'.
> Build command failed.
Error while executing process D:\Android\sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build D:\AndroidStudioProjects\camerandk\app\.externalNativeBuild\cmake\debug\arm64-v8a --target native-camera2-lib}
[1/2] Building CXX object CMakeFiles/native-camera2-lib.dir/native-camera2-lib.cpp.o
[2/2] Linking CXX shared library D:\AndroidStudioProjects\camerandk\app\src\main\jniLibs\arm64-v8a\libnative-camera2-lib.so
FAILED: cmd.exe /C "cd . && D:\Android\sdk\ndk-bundle\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=aarch64-none-linux-android --gcc-toolchain=D:/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64 --sysroot=D:/Android/sdk/ndk-bundle/sysroot -fPIC -Wno-error=format-security -Wno-error=pointer-sign -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a --sysroot D:/Android/sdk/ndk-bundle/platforms/android-21/arch-arm64 -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--no-undefined -Wl,-z,noexecstack -Qunused-arguments -Wl,-z,relro -Wl,-z,now -shared -Wl,-soname,libnative-camera2-lib.so -o D:\AndroidStudioProjects\camerandk\app\src\main\jniLibs\arm64-v8a\libnative-camera2-lib.so CMakeFiles/native-camera2-lib.dir/native-camera2-lib.cpp.o -landroid -lcamera2ndk -llog -latomic -lm "D:/Android/sdk/ndk-bundle/sources/cxx-stl/gnu-libstdc++/4.9/libs/arm64-v8a/libgnustl_static.a" && cd ."
D:/Android/sdk/ndk-bundle/toolchains/aarch64-linux-android-4.9/prebuilt/windows-x86_64/lib/gcc/aarch64-linux-android/4.9.x/../../../../aarch64-linux-android/bin\ld: cannot find -lcamera2ndk
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
ninja: build stopped: subcommand failed.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
* Get more help at https://help.gradle.org
BUILD FAILED in 48s