Visual Servoing Platform  version 3.2.0 under development (2019-01-20)
Tutorial: Building ViSP SDK for Android

Introduction

This tutorial is designed to help you build ViSP Android SDK which can be used to create Android Apps supporting ViSP Java functionalities.

Prerequisites

This tutorial assumes you have the following software installed and configured: Java Development Kit (JDK), Android SDK and NDK, Python Interpreter, Apache Ant, CMake, Ninja and ccache.

On Ubuntu or debian

  • To install Java Development Kit (JDK) follow Install Java Development Kit tutorial.
  • To install Android SDK and NDK follow the link to Android Studio, download and install Android Studio. Once installed start Android Studio using default settings. This allows to download Android SDK that will be installed in $HOME/Android/sdk on Ubuntu or in $HOME/Library/Android/sdk folder on OSX. Now to install Android NDK, with Android Studio create a new Android project. As described in this guide, from this new project enter "Android SDK" settings, select the "SDK Tools" tab and check the boxes next to LLDB, CMake, and NDK. To access to "Android SDK" settings pannel on Ubuntu go through "File \> Settings..." menu, while under OSX, go through "Android Studio \> Preferences" menu.
  • Now to install Python Interpreter (prefer versions 2.7 or 3.6), CMake, Ninja and ccache (a compiler cache for a faster build) run the following:
    $ sudo apt-get install python ant cmake-curses-gui ninja-build ccache
  • At the time this tutorial was written, on Ubuntu 16.04 LTS we got Android Studio 3.2.1, NDK 18.1 (see How to know Android NDK version) and the following other tools versions:
    $ java -version
    openjdk version "1.8.0_191"
    $ python --version
    Python 2.7.12
    $ ant -version
    Apache Ant(TM) version 1.9.6 compiled on July 20 2018
    $ cmake -version
    cmake version 3.13.2
    $ ninja --version
    1.5.1
    $ ccache --version
    ccache version 3.2.4

On Mac OSX

  • To install Java Development Kit (JDK) follow Install Java Development Kit tutorial.
  • To install Android SDK and NDK follow the link to Android Studio, download and install Android Studio. Once installed start Android Studio using default settings. This allows to download Android SDK that will be installed in $HOME/Android/sdk on Ubuntu or in $HOME/Library/Android/sdk folder on OSX. Now to install Android NDK, with Android Studio create a new Android project. As described in this guide, from this new project enter "Android SDK" settings, select the "SDK Tools" tab and check the boxes next to LLDB, CMake, and NDK. To access to "Android SDK" settings pannel on Ubuntu go through "File \> Settings..." menu, while under OSX, go through "Android Studio \> Preferences" menu.
  • Now to install Python Interpreter (prefer versions 2.7 or 3.6), CMake, Ninja and ccache (a compiler cache for a faster build) run the following:
    $ brew install python ant cmake ninja ccache
  • At the time this tutorial was written, on macOS Mojave 10.14.2 we got Android Studio 3.2.1, NDK 18.1 (see How to know Android NDK version) and the following other tools versions:
    $ java -version
    java version "11.0.1" 2018-10-16 LTS
    $ python --version
    Python 2.7.15
    $ ant -version
    Apache Ant(TM) version 1.10.5 compiled on July 10 2018
    $ cmake -version
    cmake version 3.13.2
    $ ninja --version
    1.8.2
    $ ccache --version
    ccache version 3.5

Create a workspace

Create a workspace in $HOME/visp-ws that will contain ViSP sources, build and dataset.

$ export VISP_WS=$HOME/visp-ws
$ mkdir -p $VISP_WS

Get ViSP source code

There are different ways to get ViSP source code:

  • You can download the latest release as a zip or a tarball. Once downloaded, uncompress the file using either
    $ tar xvzf visp-x.y.z.tar.gz -C $VISP_WS
    or
    $ unzip visp-x.y.z.zip -d $VISP_WS
  • You can also download a daily snapshot. Once downloaded, uncompress the file using
    $ tar xvzf visp-snapshot-yyyy-mm-dd.tar.gz -C $VISP_WS
  • Or you get the cutting-edge ViSP from GitHub repository using the following command
    $ cd $VISP_WS
    $ git clone https://github.com/lagadic/visp.git

We suppose now that ViSP source is in the directory $VISP_WS/visp. The following should be adapted if you downloaded ViSP from a zip or tarball. In that case, the source is rather in something like $VISP_WS/visp-x.y.z.

Build ViSP Android SDK

Note that the scripts for building the SDK are included in the source code.

In the workspace create a build folder

$ mkdir $VISP_WS/visp-build-android-sdk

Enter the directory $VISP_WS/platforms/android having the python build script and check which are the command line options that are available.

$ cd $VISP_WS/visp/platforms/android
$ python build_sdk.py --help

Generally the script has to be used like:

$ python build_sdk.py --config <ndk-*.config.py> --sdk_path <path-to-Android-Sdk> --ndk_path <path-to-Android-Sdk>/ndk-bundle <installation-directory> <visp-source-code-directory>

In $VISP_WS/visp/platforms/android folder we provide different NDK config files:

$ ls ndk-*.config.py
ndk-10.config.py ndk-16.config.py ndk-17.config.py ndk-18.config.py

The file that should be used after --config option should match your NDK version (see How to know Android NDK version).

Above command will build SDK for multiple Android architectures. If you're aware on what Android architecture you'll be working on (refer here), say x86_64, you can do a minimal build by changing contents of ndk-*.config.py file

ABIs = [
ABI("5", "x86_64", None)
]

This will speed up the installation process.

Once build ViSP Android SDK will be available in $VISP_WS/visp-build-android-sdk/ViSP-android-sdk/sdk folder. Its content should be similar to the following:

$ cd $VISP_WS/visp-build-android-sdk/ViSP-android-sdk/sdk
$ find . -type d -depth 3
./native/libs/armeabi-v7a
./native/libs/x86
./native/libs/arm64-v8a
./native/libs/x86_64
./native/3rdparty/libs
./native/staticlibs/armeabi-v7a
./native/staticlibs/x86
./native/staticlibs/arm64-v8a
./native/staticlibs/x86_64
./native/jni/abi-x86_64
./native/jni/include
./native/jni/abi-x86
./native/jni/abi-arm64-v8a
./native/jni/abi-armeabi-v7a
./etc/data/wireframe-simulator
./etc/data/robot-simulator
./java/res/values
./java/src/org

On Linux or Debian

For example, on Ubuntu the command might look like

$ python build_sdk.py --config ndk-18.config.py --sdk_path $HOME/Android/Sdk --ndk_path $HOME/Android/Sdk/ndk-bundle $VISP_WS/visp-build-android-sdk $VISP_WS/visp

On Mac OSX

For example, on OSX the command might rather look like

$ python build_sdk.py --config ndk-18.config.py --sdk_path $HOME/Library/Android/sdk --ndk_path $HOME/Library/Android/sdk/ndk-bundle $VISP_WS/visp-build-android-sdk $VISP_WS/visp

Known issue

If you're experiencing problems with ccache or if you don't install ccache, you can try a build without it adding --no_ccache command line option like the following on Ubuntu:

$ python build_sdk.py --no_ccache --config ndk-18.config.py --sdk_path $HOME/Android/Sdk --ndk_path $HOME/Android/Sdk/ndk-bundle $VISP_WS/visp-build-android-sdk $VISP_WS/visp

Tips & tricks

How to know Android NDK version

  • Start Android Studio
  • on Ubuntu enter File > Settings... menu, while on Mac OSX enter Android Studio > Preferences... menu select Android SDK in the left part and selct SDK Tools tab to see which is the NDK version that you are using:
    img-android-ndk-version.png

Next tutorial

You are now ready to follow Tutorial: Creating a simple Android App with ViSP where you'll be creating a sample Android App using ViSP SDK.