# osgearth-collect **Repository Path**: gaoyunjun/osgearth-collect ## Basic Information - **Project Name**: osgearth-collect - **Description**: 本项目为fork自github(https://github.com/thahemp),对代码做了一定的修改,编译通过的osgearth Android版程序 - **Primary Language**: C++ - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 11 - **Created**: 2024-12-19 - **Last Updated**: 2024-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 本项目为 fork 自[github thahemp 的仓库](https://github.com/thahemp),对代码做了一定的修改,编译通过的 osgearth Android 版程序 软件架构 # OSGEarthAndroidDemo 编译笔记 - 前期准备 - 下载 linux 的 ndk,本人已经将需要使用的 ndk 版本分享到网盘 - [r10e](https://cloud.189.cn/t/a6ryQry6BJra) - [r11c](https://cloud.189.cn/t/yuEZFrFrINzi)(建议使用) - 下载 Android SDK 本文根据 osgearth 论坛第三方作者[thahemap](http://forum.osgearth.org/OSG-3-2-1-and-OSGEarth-2-7-for-Android-td7588377.html#a7588453)的仓库代码完成 **编译环境为 Win10 的 Ubuntu 子系统,版本为 18.04** ## 编译前的环境准备 - 环境变量设置 - 设置本地 ndk 环境变量 - 设置本地 Android sdk 环境变量 - 针对当前用户设置,可以在~/.bashrc 文件底部增加内容 ```xml export ANDROID_HOME="/mnt/f/DevelopmentTools/sdk" export ANDROID_NDK="/mnt/f/DevelopmentTools/linux/android-ndk-r11c-linux-x86_64/android-ndk-r11c" export PATH="${PATH}:${ANDROID_HOME}:/usr/lib/x86_64-linux-gnu:${ANDROID_HOME}/tools:${ANDROID_HOME}/platform-tools:${ANDROID_NDK}:/usr/include" ``` **注: 路径需要替换为自己的本地路径,对于 win10 的 linux 子系统,windows 盘符都是挂接在/mnt 目录下,例如 windows 的 C 盘在 linux 子系统中对应目录为/mnt/c** - 随后需要通过 linux 下载指定的依赖包,因此建议将 apt 仓库地址设置为[国内镜像地址](https://www.cnblogs.com/xiaojf/p/11105626.html) - 参考[CSDN 网友的编译经验](https://blog.csdn.net/zhuyunier/article/details/82843958),针对 64 位 Ubuntu 系统,建议安装 Linux 的编译环境所需依赖包 ``` sudo apt-get install autoconf automake ant autopoint cmake build-essential libtool m4 patch pkg-config protobuf-compiler ragel subversion unzip git ``` - [OSG 官方](http://www.openscenegraph.org/index.php/download-section/dependencies)对于 linux 系统在编译时所需要的依赖环境,也给出了依赖包下载代码 `apt-get build-dep openscenegraph`,建议也一并安装 - 在编译osgearth-android,可能会提示:fatal error: GLES2/gl2.h: No such file or directory,这里应该是需要安装OpenGL-es,参考[此链接](https://google.github.io/mediapipe/getting_started/gpu_support.html#opengl-es-setup-on-linux-desktop),安装下面的组建即可 ``` sudo apt-get install mesa-common-dev libegl1-mesa-dev libgles2-mesa-dev sudo apt-get install mesa-utils ``` ## 开始编译 1. 编译[osg-android](https://github.com/thahemp/osg-android),按照 github 仓库中给出的建议修改为本地指定目录,执行该项目根目录下的 buildOSGAndroid.sh 2. 编译[osgearth-android](https://github.com/thahemp/osgearth-android),同样需要修改 buildOSGEarthAndroid.sh 文件内的路径为本地路径,随后执行 buildOSGEarthAndroid.sh 3. 编译[OSGEarthAndroidDemo](https://github.com/thahemp/OSGEarthAndroidDemo) (具体可参考链接中的 readme 说明) **注意:在编译 OSGEarthAndroidDemo 时,如果将 Application.mk 内的 APP_PLATFORM 设置为 19(事实上是小于 19 的版本),编译时会报错误![platform<19](image/platform-19.png),不用理会,再将 APP_PLATFORM 版本号修改为 27,重新编译,会在 OSGEarthAndroidDemo/Map/app/src/osgearth/libs 目录下生成新的 so 文件,因为 build.gradle 中配置 so 文件目录为 OSGEarthAndroidDemo/libs 目录下,需要将该目录下文件拷贝到 OSGEarthAndroidDemo/libs 目录下,运行 Android 程序即可** **如果直接使用 platform 为 27 的版本执行编译,会报下面的错误![platform27](image/platform-27.png),同理,将 Application.mk 内的 APP_PLATFORM 设置为 19,重新编译即可** - 编译结束后,用 Android Studio 加载 OSGEarthAndroidDemo 中的 Map 项目,将编译好的 so 文件(位于 Map/app/src/osgearth/libs 目录下)拷贝到 Map/app/libs 中,运行程序即可 编译完成后的 Android 程序演示效果 ![osgearth-app-demo](image/osgearth-app-demo.jpg) ## 问题记录 1. 如果提示“XXXX \r 不存在”等错误,请确认使用的是notpad++、noteplus等文本编辑工具,避免使用windows自带的“笔记本”工具,同时文件保存后的回车符应使用LF而非CRLF等格式。因为linux系统对回车符定义与windows不同。 2. 如果提示“The CXX compiler identification is unknown”,是因为没有安装g++,请执行apt-get install g++命令安装依赖后重新执行sh文件 3. 编译osgearth-Android时 - 如果提示“cmake Could NOT find ZLIB”,需要手动安装zlib,在osgearth-android文件夹下存在zlib的源码,进入该目录后,参考[此链接](https://blog.csdn.net/Qzx9059/article/details/88542638),依次执行 ``` ./configure make make check sudo make install ``` - 如果提示“Could NOT find PNG”,也可以参考[上述链接](https://blog.csdn.net/Qzx9059/article/details/88542638),依次执行 ``` sudo apt-get install libjpeg-dev sudo apt-get install libpng-dev sudo apt-get install libtiff-dev ```