Getting Started with the Tango C API

In this tutorial, we’ll go through setting up your build environment and compiling and running your first “Hello Tango” project using the C API, which will run sample code and display the pose data from your device.


To successfully follow this guide, you will need:

  • Android Studio.
  • The most recent version of the Android NDK. If you haven’t already installed it, you can do so from inside Android Studio—see the “Installing the NDK” section further down this page.
  • Experience developing Android apps. If you have never created an Android app before, you can get started with our Building Your First App tutorial.
  • The sample project. This includes the Tango C API files, which you can find in the subfolder namedtango_client_api after you download the project. For download instructions, see the next section.
  • A Tango Tablet Development Kit. You can build the code without one, but you won’t be able to run it.

Download the sample project

The sample project is hosted on GitHub. You can download it as a zip file or use git to clone the repository:

git clone

You should now have a directory called tango-examples-c on your machine. Within this directory you should see a subdirectory called cpp_basic_examples, which contains the code for this guide.

Install the NDK

  1. Open Android Studio. You can create a new project or load a previous one.
  2. Do one of the following:

    If you are using Windows or Linux: On the File menu, click Settings.

    If you are using Mac OS: On the Android Studio menu, click Preferences.

  3. In the left-side menu of the Settings dialog, click the arrow to the left of Appearance & Behaviorto view its submenu.

  4. In the list that appears, click the arrow to the left of System Settings to view its submenu.

  5. In the System Settings submenu, click Android SDK.
  6. In the main view on the right side of the dialog box, click the SDK Tools tab.

  7. In the Name column, click Android NDK.

  8. Click OK.

    The Confirm Change dialog appears.

  9. Click OK.

    The SDK Quickfix Installation dialog appears and displays messages about the installation process and a progress bar.

  10. After the installation finishes and the Done message appears, click Finish.

If you want to confirm that the NDK is installed, follow the steps above to navigate to the SDK Tools tab in the Settings folder. The Android NDK option should be selected.

Import the project into Android Studio

  1. Do one of the following:
    • Open Android Studio.
    • If you are already in Android Studio with a project loaded, close the project.

    Either action takes you to the Welcome to Android Studio screen.

  2. Select Import Project (Eclipse ADT, Gradle, etc.). In older versions of Android Studio, this may be Import Non-Android Studio project or simply Import Project.
  3. In the Select Eclipse or Gradle Project to Import dialog, navigate to the repository you just cloned. Choose the cpp_basic_examples directory and then click OK.

Set up your environment

  1. In the Gradle Scripts directory, open the file and then add the ndk.dir property under the sdk.dir property that is already there:

  2. If you are using Windows, you may need to edit your build.gradle file to fix the ndkbuild path. Open the file and change the ndkbuild path from ndk-build to ndk-build.cmd.
// ...
task ndkBuild(type: Exec) {
    Properties properties = new Properties()
    def ndkbuild = properties.getProperty('ndk.dir', null)+"/ndk-build.cmd"
    commandLine ndkbuild, '-C', file('src/main/jni').absolutePath

Connect your device

If you haven’t already done so, connect your Tango device to your computer.

Build and run an application

Within the basic examples project you loaded, you have a choice of several different “hello”-style apps to build and run. For this tutorial, we’ll choose “Hello Motion Tracking.”

  1. On the toolbar, view the Run/Debug Configuration field and make sure hello_motion_tracking is the active configuration. If it is not, click the field and select it.

  2. Do one of the following:
    • On the Run menu, click Run.
    • On the toolbar, click the Run button (the green arrow).
  3. In the Device Chooser dialog, select Choose a running device, then select your Tango tablet, and then click OK.

View the raw pose data in logcat

The logcat output appears automatically in the bottom part of Android Studio.

To see the logcat output in your terminal:

  • Use the adb logcat command:
sdk-path/platform-tools/adb logcat

Here is a brief example of the pose data that appears in your terminal:

I/cpp-hello-tango(13862): Position: -0.007565, -0.000628,
-0.016770. Orientation: 0.642147, -0.026346, 0.765854, 0.765854

Next steps

Now that you have learned how to set up your environment for development with the Tango C API, proceed to the following links to learn how to use specific features of Tango in your app:

Also, take a look at the rest of our code samples on Github.

tango Asked on 2016年11月2日 in 虚拟现实VR.
Add Comment
0 Answer(s)

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.