MacOS编译hello_xr——记一次CMake搜索路径限制导致的ANDROID_NATIVE_APP_GLUE not found

  1. 首先,由于之前使用过Unity, 系统已经装好了android SDK和NDK, 所以在hello_xr文件夹下, 用local.properties文件来设置系统中二者的路径:
bash 复制代码
sdk.dir=/Applications/Unity/Hub/Editor/2022.3.48f1c1/PlaybackEngines/AndroidPlayer/SDK/
# ndk.dir=/Applications/Unity/Hub/Editor/2022.3.48f1c1/PlaybackEngines/AndroidPlayer/NDK

这里由于后面编译时, 系统提示ndk.dir这种方式已经落伍了,不推荐使用,所以注释掉了, 改为在build.gradle中配置其路径, 版本号也要进行对应的修改, build.gradle中修改后的对应处如下所示:

bash 复制代码
    android.ndkPath = "/Applications/Unity/Hub/Editor/2022.3.48f1c1/PlaybackEngines/AndroidPlayer/NDK/"
    ndkVersion "23.1.7779620"
  1. 编译期间,又遇到一个找不到ANDROID_NATIVE_APP_GLUE的问题, 当时报错如下:
bash 复制代码
CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
  Please set them or make sure they are set and tested correctly in the CMake files:
  /Users/Documents/OpenXR-SDK-Source/src/tests/c_compile_test/ANDROID_NATIVE_APP_GLUE
     used as include directory in directory /Users/Documents/OpenXR-SDK-Source/src/tests/c_compile_test
  /Users/Documents/OpenXR-SDK-Source/src/tests/list_json/ANDROID_NATIVE_APP_GLUE
     used as include directory in directory /Users/Documents/OpenXR-SDK-Source/src/tests/list_json

搜了一下,对应处的CMakeLists.txt是这样写的:

bash 复制代码
#......
elseif(ANDROID)
    set(OPENGL_INCOMPATIBLE TRUE) #不兼容OPEN GL
    find_path(
        ANDROID_NATIVE_APP_GLUE android_native_app_glue.h
        PATHS ${ANDROID_NDK}/sources/android/native_app_glue  
    )

也就是说, 在给定的目录下查找android_native_app_glue.h这个文件, 找到后将其所在目录赋给ANDROID_NATIVE_APP_GLUE.

于是确认了下系统中该目录是否存在该文件, 结果发现是有的.

那么为什么查找结果是not found呢?

请教了一下ChatGPT, 列出许多种可能, 最后定位到是这个问题:

在交叉编译时,CMake 的 CMAKE_FIND_ROOT_PATH 或 CMAKE_SYSROOT 参数可能会限制搜索路径。可以在

CMake 配置文件中临时打印这些变量的值,确保没有限制搜索范围:

bash 复制代码
message("CMAKE_FIND_ROOT_PATH is: ${CMAKE_FIND_ROOT_PATH}")
message("CMAKE_SYSROOT is: ${CMAKE_SYSROOT}")

如果它们包含限制,可以通过临时调整 CMAKE_FIND_ROOT_PATH_MODE_INCLUDE 和 CMAKE_FIND_ROOT_PATH_MODE_LIBRARY 的值,使其允许在本地路径中搜索:

bash 复制代码
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE BOTH)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY BOTH)

经过调整后,就编译成功啦

相关推荐
モンキー・D・小菜鸡儿1 小时前
Android Jetpack Compose 基础控件介绍
android·kotlin·android jetpack·compose
无风之翼1 小时前
android15 休眠唤醒过程中有时候屏幕显示时间一闪而过
android·锁屏
方白羽3 小时前
Android全局悬浮拖拽视图
android·app·客户端
Jerry4 小时前
Compose 高级状态和附带效应
android
2501_916007476 小时前
苹果手机iOS应用管理全指南与隐藏功能详解
android·ios·智能手机·小程序·uni-app·iphone·webview
LFly_ice6 小时前
Nest-管道
android·java·数据库
ab_dg_dp8 小时前
android bugreport 模块源码分析
android
2501_915106329 小时前
全面理解 iOS 帧率,构建从渲染到系统行为的多工具协同流畅度分析体系
android·ios·小程序·https·uni-app·iphone·webview
繁星星繁9 小时前
【Mysql】数据库基础
android·数据库·mysql
李坤林9 小时前
Android 12 中 App 与 SurfaceFlinger(SF)的 Vsync 通信机制
android·surfaceflinger