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)

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

相关推荐
敲上瘾25 分钟前
磁盘到 inode:深入理解 Linux ext 文件系统底层原理
android·linux·运维·文件系统
hewence134 分钟前
Kotlin CoroutineScope解密
android·开发语言·kotlin
2501_946490381 小时前
xR+AR双虚拟技术在晚会舞台的协同落地实践——以浙江卫视苏宁易购超级秀为例
ar·xr·hirender·hecoos
遇雪长安1 小时前
高通安卓设备DIAG端口启用指南
android·adb·usb·dm·qpst·diag·qxdm
2501_946490381 小时前
xR虚拟制片技术在游戏IP展演中的高密度拍摄落地实践——基于hecoos xR+UE4的技术实现
tcp/ip·游戏·xr
华章酱1 小时前
MySQL EXPLAIN 完全解读:从执行计划到索引优化
android·数据库·mysql
2501_915921431 小时前
Fastlane 结合 AppUploader 来实现 CI 集成自动化上架
android·运维·ci/cd·小程序·uni-app·自动化·iphone
贤泽2 小时前
Android 15 AOSP Notification分析
android
特立独行的猫a2 小时前
腾讯Kuikly多端框架(KMP)实战:轮播图的完整实现
android·harmonyos·轮播图·jetpack compose·kuikly
2501_915921432 小时前
iOS 抓包怎么绕过 SSL Pinning 证书限制,抓取app上的包
android·网络协议·ios·小程序·uni-app·iphone·ssl