Note: This tutorial assumes that you have completed the previous tutorials: building native ROS packages.
(!) Please ask about problems and questions regarding this tutorial on 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 Sample Application using Binary Distribution

Description: This tutorial presents an example Android application which uses the binary distribution of the cross compiled ROS libraries for Android. It is based on the ANT build system and is intended to serve a starting point for a custom application.

Keywords: Native Activity

Tutorial Level: BEGINNER

Next Tutorial: android_ndk/Tutorials/How to cross-compile any ROS package

Using the Android NDK ROS binary distribution

If you followed the previous tutorial, you must have realized that cross compiling the ROS packages to Android is a very resource and time consuming task. For that reason, the build scripts can generate a stand alone binary distribution of the cross compiled libraries.

This distribution is formed by a single directory which can act as an Android NDK module, that is, a series of libraries which can be set as build dependencies for an Android NDK project.

In this tutorial will use a sample Android Native application configured to use the pre built ROS NDK module.


  • Before being able to build the application we need to have the Android development tools installed. We recommend following this rosjava tutorial which explains how to install the required Java software and the Android Studio SDK package.

  • Using the Android SDK Manager, included in the Android Studio package, make sure that the following items are installed:

    • Android 1.5 (API 3) -> SDK Platform

    • Android 4.0 (API 14) -> SDK Platform

    • Tools -> Android SDK Build-Tools 21, (19.1 also works)

  • Install ant on your system:

    $ sudo apt-get install ant
  • You will also need to download the Android NDK. This demo code was tested using the r8e and r10c versions. For a different application, the exact version of the NDK that you need to use will depend on the requirements of your application. After downloading, for newer versions (which are a .bin file) follow the installation instructions. For older versions (.tar.gz), just untar it somewhere.

Get the files

sample_app. Sample app with ANT configuration.

roscpp_android_ndk Android NDK module contains all the cross compiled ROS packages(big download, aprox 600M)

Save both files in the same directory and untar them. Take into account that the NDK module will expand into a 3GB directory.

Modify the paths for your system

We need to modify 3 paths that are specified in two different files in the sample_app directory.

The first two are the location of the NDK binaries and the ROS NDK module. Both things are configured in the custom_rules.xml file. Let's look at one example configuration:

  • 1 <project name="custom_rules" default="debug">
    2     <target name="-pre-build">
    3       <exec executable="/opt/ndk/ndk-build" failonerror="true">
    4         <env key="NDK_MODULE_PATH" path="/home/tulku/osrf/" />
    5         </exec>
    6     </target>
    7 </project>

Line 3 states the path to the ndk-build binary, which will be inside the NDK installation.

  • for example :install ndk from android-stuido 2.2 you can set up as($sdk path)/ndk-bundle/build/ndk-build

Line 4 states the path of the directory that contains the roscpp_android_ndk directory.

  • do not need to add roscpp_android_ndk in it.

The last thing that we need to configure is the path to the Android SDK, which is specified in the file:

  •   (Ignore the warnings in lines 1 to 6)
      7 # location of the SDK. This is only used by Ant
      8 # For customization when using a Version Control System, please read the
      9 # header note.
     10 sdk.dir=/opt/sdk

Line 10 should be modified to point to the location where the Android SDK was installed, which may not be necessarily along with the Android Studio package.


After the paths are configured, you just need to compile the app using ANT. Run the following command from inside the sample_app directory.

  • $ ant debug

The resulting APK will be located in the bin directory inside the sample_app directory.

Installing and Testing

To install the new application on a device and test it, please follow the last two steps found in this tutorial

Wiki: android_ndk/Tutorials/Building The Example Applications using the Binary Distribution (last edited 2017-01-07 03:47:00 by xy1zzz)