在Android上运行ROS程序一般使用rosjava-android。但是也可以直接利用NDK编译成so文件移植到Android上。当然移植过程也并不简单。 下面是一个简单的例子。 安装cmake(>3.14)新版本的cmake增加了对Android cross compile的支持,所以我们要安装新版本的cmake。 wget -q https://github.com/Kitware/CMake ... .14.0-rc4.tar.gztar -x*** cmake-3.14.0-rc4.tar.gzcd cmake-3.14.0-rc4/env CC=$(which clang) CXX=$(which clang++) ./bootstrap --prefix=/usr --parallel=4makesudo make installcd ..安装clang新版本的NDK默认使用clang进行编译。所以我们需要安装clang。clang的安装方式可以参照这里 安装NDKwget -q https://dl.google.com/android/re ... nux-x86_64.zipunzip -qq android-ndk-r18b-linux-x86_64.zipexport NDK_ROOT=$(pwd)/android-ndk-r18b设置cmake toolchaingit clone https://github.com/BluewhaleRobot/rostoolchainexport TOOLCHAIN_ROOT=$(pwd)/rostoolchain安装Boost-androidgit clone https://github.com/moritz-wundke/Boost-for-Androidmkdir boost_libscd Boost-for-Android./build-android.sh --boost=1.68.0 --prefix=$(pwd)/../boost_libs $NDK_ROOTcd ..#set up boostexport INSTALL_PREFIX=/opt/ros/armsudo mkdir -p $INSTALL_PREFIX/includesudo mkdir -p $INSTALL_PREFIX/libsudo cp -rf boost_libs/armeabi-v7a/include/boost-1_68/boost $INSTALL_PREFIX/include/sudo cp boost_libs/armeabi-v7a/lib/*.a $INSTALL_PREFIX/lib/设置ROS workspacemkdir -p arm/srccd arm/srcgit clone https://github.com/ros/catkin --depth=1git clone https://github.com/ros/common_msgs --depth=1git clone https://github.com/ros/gencpp --depth=1git clone https://github.com/jsk-ros-pkg/geneus --depth=1git clone https://github.com/ros/genlisp --depth=1git clone https://github.com/ros/genmsg --depth=1git clone https://github.com/RethinkRobotics-opensource/gennodejs --depth=1git clone https://github.com/ros/genpy --depth=1git clone https://github.com/ros/message_generation --depth=1git clone https://github.com/ros/message_runtime --depth=1git clone https://github.com/BluewhaleRobot/ros_comm --depth=1git clone https://github.com/ros/ros_comm_msgs --depth=1git clone https://github.com/BluewhaleRobot/rosconsole --depth=1git clone https://github.com/BluewhaleRobot/roscpp_core --depth=1git clone https://github.com/ros/std_msgs --depth=1编译工作空间cd .../src/catkin/bin/catkin_make -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_ROOT/toolchain-arm.cmake -DCATKIN_WHITELIST_PACKAGES="" -DBUILD_SHARED_LIBS=OFFsudo cp -rf devel/lib/*.a $INSTALL_PREFIX/lib/sudo cp -rf devel/lib/pkgconfig $INSTALL_PREFIX/lib/export PKG_CONFIG_PATH=$INSTALL_PREFIX/lib/pkgconfig编译你自己的代码现在把你的代码放置到此工作空间内,然后像之前编译工作空间一样。 ./src/catkin/bin/catkin_make -DCMAKE_TOOLCHAIN_FILE=$TOOLCHAIN_ROOT/toolchain-arm.cmake -DCATKIN_WHITELIST_PACKAGES="" -DBUILD_SHARED_LIBS=OFF编译出so文件或.a文件之后,利用JNI写一个包装程序,然后通过java调用。这样就可以在Android app里面使用了。
|