In this tutorial, we‘ll go through setting up your build environment and compiling and running your first "Hello Tango" project using the Java API, which will run sample code and display the pose data from your device.
在本教程中,我们将尝试设置你的开发环境,使用Java API编译并运行你的第一个“Hello Tango”工程。它将运行样本代码,并且展示你的设备的姿态数据。
Prerequisites提前条件
To successfully follow this guide, you will need:要成功进行该指示,你需要:
-
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 Java API files, which you can find in the subfolder named TangoReleaseLibs 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 https://github.com/googlesamples/tango-examples-java.git
You should now have a directory called tango-examples-java
on your machine. Within this directory you should see a subdirectory called java_basic_examples
, which contains the code for this guide.
Import the project into Android Studio
-
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.
-
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.
-
In the Select Eclipse or Gradle Project to Import dialog, navigate to the repository you just cloned. Choose the
java_basic_examples
directory and then click OK.
Connect your device
If you haven‘t already connected your Tango device to your computer, you should do so now.
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."
-
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.
-
Do one of the following:
- On the Run menu, click Run.
- On the toolbar, click the Run button (the green arrow).
-
In the Device Chooser dialog, select Choose a running device, then select your Tango tablet, and then click OK.
See logcat for the raw pose data
You can see logcat output automatically in the bottom part of Android Studio.
If you want to see it in your terminal, type
adt_path/sdk/platform-tools/adb logcat
You will see the pose data being printed in your terminal:
I/MainActivity( 6010): Translation: 0.020329, 0.013915, -0.008571 | Rotation: 0.581630, 0.014597, -0.021857, 0.813029
Add to your own project
The Tango SDK for Java components are distributed on Bintray and are available through the JCenter repository when using Maven.
-
First, add
jcenter()
to yourbuild.gradle
file so Gradle can find the AARs. For example:allprojects {
repositories {
jcenter()
}
} -
Add the appropriate dependencies to the
build.gradle
files in your modules. You can determine this by looking at the samples‘build.gradle
files to see what each one needs. For example, our motion tracking sample uses:dependencies {
compile ‘com.google.tango:sdk-base:LATEST_VERSION‘
compile ‘com.google.tango:support-base:LATEST_VERSION‘
}The latest version looks like
1.51
and can be found on the downloads page. This code indicates that an application similar to the motion tracking sample needs sdk-base and support-base. This will also recursively fetch dependent libraries.
Once this is done for all of the required libraries, you will be able to reference code in the Tango SDK in your app.
If you are using your own build system, the Tango libraries are also available from the downloads page.
Next steps
Now that you have learned how to set up your environment for development with the Tango Java API, proceed to the following links to learn how to use specific features of Tango in your app:
Also, take a look at our code samples on Github.