(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Building native ROS packages

Description: This tutorial show how to build native ROS nodes using the Android NDK

Keywords: android native NDK

Tutorial Level: BEGINNER

Next Tutorial: Testing the sample application using a Native Activity android_ndk/Tutorials/Building The Example Applications using the Binary Distribution

Building native ROS packages

Prerequisites

Installing dependencies

  • $ sudo apt-get update
    $ sudo apt-get install curl git

Installing latest version of Docker

Ubuntu:

(Taken from https://docs.docker.com/installation/ubuntulinux/#ubuntu-trusty-1404-lts-64-bit)

Install using the available script from docker.

  • $ curl -sSL https://get.docker.com/ubuntu/ | sudo sh

To verify that everything has worked as expected:

  • $ sudo docker run -i -t ubuntu /bin/bash

Which should download the Ubuntu image, and then start bash in a container.

Then you should get something like this:

  • root@20dd792aa8e9:/#

This means that everything is OK, close the docker container:

  • root@20dd792aa8e9:/# exit

And we're ready to go!

Cloning the roscpp_android repository

This repository contains the scripts to build the container and do the cross-compilation of the ROS libraries. Create a folder and clone the repository inside it.

  • $ mkdir ~/ros-android-ndk
    $ cd ~/ros-android-ndk
    $ git clone https://github.com/ekumenlabs/roscpp_android.git
    $ cd roscpp_android

Building the container and cross-compiling

The script can generate two different types of output. The raw mode and the portable one:

  1. raw mode is intended to be used during porting new libraries to Android. It uses symbolic links to generate the Android NDK module, which saves space.

  2. portable copies all the required files to the Android NDK module and creates a .tar.gz with it. This file is intended to be used when distributing pre compiled ROS Android libraries.

By default, when running:

  • $ ./do_docker.sh

will generate an output directory in the current directory, and build it in raw mode. To change the output path:

  • $ ./do_docker.sh --raw /output/path

To generate a portable binary in output/roscpp_android_ndk.tar.gz,

  • $ ./do_docker.sh --portable

    You can also use '--delete-image' to remove the docker image and start building it again, or '--delete-tmp' to delete the content of /var/lib/docker/tmp in order to save space on your machine

Now you can go grab something to drink, this takes some time.

What does do_docker.sh do?

The script first creates a docker container based on Ubuntu 14.04 and install all the Ubuntu dependencies, then it fetches all the library dependencies and the ROS packages specified in the ndk.rosinstall file. Lastly, it cross-compiles the libraries and runs ´catkin_make´ to build the ROS packages.

Verifying the cross-compilation

If everything went well you should see the following banner

  • summary of what just happened:
      target/      was used to build static libraries for ros software
        include/   contains headers
        lib/       contains static libraries
      roscpp_android_ndk/     is a NDK sub-project that can be imported into an NDK app
      sample_app/  is an example of such an app, a native activity
      sample_app/bin/sample_app-debug.apk  is the built apk

This means that all the ROS packages have been correctly built. Congratulations!

Wiki: android_ndk/Tutorials/BuildingNativeROSPackages (last edited 2016-01-24 15:16:35 by jcerruti)