Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can use the rosjava API even with otherwise fully native code by using the JNI.

If you really don't want to use Java then I have some hints here (I hope I have time in the future to write that down properly). Be warned tough that it took me many weeks of fighting various build systems, fixing code and hunting down the right flags!

All you actually need to communicate is roscpp and its dependencies. Basically you start with rosinstall_generator roscpp --rosdistro melodic --deps and go from there. Throw out everything you don't really really need. Some libraries that ROS uses are cumbersome to cross-compile but easily stripped out by removing a few lines.

I had successs with Boost 1.69 using https://github.com/moritz-wundke/Boost-for-Android/ (1.70 didn't work) and a current cmake (3.15.5 for me).

I have a folder where I make install all third party dependencies into (like boost or eigen). Everything else is in a normal catkin workspace using the following config:

catkin config --install --cmake-args \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo \
    -DANDROID_ABI=arm64-v8a \
    -DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
    -DANDROID_TOOLCHAIN=clang \
    -DANDROID_NDK=$ANDROID_NDK_HOME \
    -DANDROID_NATIVE_API_LEVEL=26 \
    -DCMAKE_FIND_ROOT_PATH=<a whole bunch of paths here> \
    -DANDROID_STL=c++_shared \
    -DBoost_DEBUG=ON \
    -DBoost_COMPILER=-clang \
    -DBoost_ARCHITECTURE=-a64 \
    -DBUILD_SHARED_LIBS=ON \
    -DBoost_USE_STATIC_LIBS=ON

CMAKE_FIND_ROOT_PATH is a list of paths where all the third party libraries are installed to, as well as the catkin install folder. Every .so that's ever needed is in there basically so other packages can find it.

I spent a long time getting a working python 2 for Android. I got python itself running, but haven't managed to get pip and python libraries to cross-compile. You actually don't need any python just for roscpp tough ;)

I haven't gotten image_transport working, because that relies on some python modules. So I have to transmit uncompressed images which quickly saturates even a gigabit link!

Some ROS packages didn't compile out of the box and needed a few small fixes.


As for linking everything into our Android application: I'm using Android's cmake (with Android Studio 3.5.1 and NDK 20.0.5594570) which makes integration of a catkin package quite easy actually: If you've set your CMAKE_FIND_ROOT_PATH properly in the Android project you can just use find_package(roscpp). I don't have any experience using the old ndk-build based system and I warmly recommend cmake instead ;)

But basically: If you use an install layout in your catkin workspace (catkin config --install) you will get an install folder that contains all the .so and header files that you can just link to your code.


Another option might be to use Termux and compile everything you need on the device itself.

Good luck!