Android 有一些 NDK 示例无法为我编译。
鉴于:
我收到以下 C 编译错误:
ndk-samples/native-activity/app/src/main/cpp/main.cpp:50:5: error: use of undeclared identifier 'android_set_abort_message'
android_set_abort_message("failed for format error message");
native-activity/app/src/main/cpp/main.cpp:127:38: error: 'AChoreographer_getInstance' is unavailable: introduced in Android 24
AChoreographer_postFrameCallback(AChoreographer_getInstance(), Tick, this);
ndk/25.2.9519653/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/android/choreographer.h:95:17: note: 'AChoreographer_getInstance' has been explicitly marked unavailable here
AChoreographer* AChoreographer_getInstance() __INTRODUCED_IN(24);
这似乎 ANDROID_API 没有通过 C 编译步骤。 我怎样才能做到这一点?
我尝试将这些添加到示例 CMakeLists.txt 并重新运行上述 cmake,然后生成命令。
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 24) # API level
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_STL_TYPE gnustl_static)
set(ANDROID_PLATFORM 24) # API level
set(CMAKE_ANDROID_API 24) # API level
android studio 和命令行指令都在自述文件中:https://github.com/android/ndk-samples?tab=readme-ov-file#build-and-run
ndk 25.2.9519653
不能那样做。他们需要更新的 NDK:https://github.com/android/ndk-samples/blob/main/build-logic/src/main/java/com/android/ndk/samples/buildlogic/Versions.kt#L9
cmake -DCMAKE_SYSTEM_NAME="Android" -DCMAKE_SYSTEM_VERSION="24" -DCMAKE_ANDROID_NDK="${NDK_HOME}" -DANDROID_NDK="${NDK_HOME}" -DANDROID_PLATFORM=android-24 ..
仅使用 CMake 无法构建这些。您需要运行 Gradle 来构建应用程序的非本机部分。