Cloud Anchors for Android Quickstart

Get started with Cloud Anchors. This guide shows you how to:

  • Set up your development environment for Cloud Anchors
  • Try out hosting and resolving anchors in a sample app

This guide assumes that you have already installed and configured the ARCore SDK for Android. If not, see the Quickstart for Android for installation and setup steps.

If you are new to working with anchors, see Working with Anchors for an introduction.

Requirements

To use Cloud Anchors, you'll need:

Hardware

Software

  • Android Studio version 3.0 or later with Android SDK Platform version 7.0 (API level 24) or higher.

  • The ARCore SDK for Android. To get the SDK, you can do either of the following:

    • Download the ARCore SDK for Android and extract it.

    • Clone the repository with the following command:

      git clone https://github.com/google-ar/arcore-android-sdk.git

Use Cloud Anchors

Set up your development environment for working with Cloud Anchors and try out the sample app.

Open the sample app in the SDK

The helloarcloudanchor sample app is included with the ARCore SDK for Android.

In Android Studio, you can find it under:
app/java/com.google.ar.core.examples.java

Set up anchor ID sharing

The sample app uses Firebase for sharing Cloud Anchor IDs between devices. You can use a different solution in your own apps.

Set up Firebase storage in the sample app for sharing anchor IDs between user devices:

  1. Follow steps 1 through 5 in the Firebase instructions for manually adding Firebase to your app.
  2. Download the google-services.json file generated as part of adding Firebase to your app.
  3. In Android Studio, add the google-services.json file to your project's module folder. Typically, this is the app/ folder.

Add an API Key

To use Cloud Anchors, you'll need to add a Google ARCore Cloud Anchor API Key to your app.

  1. Obtain an API Key. See Setting up API keys in the Google Cloud Platform Console Help Center if you are new to working with API keys.

  2. Enable the ARCore Cloud Anchor API for your Google Cloud Platform project.

  3. In Android Studio, add your ARCore Cloud Anchor API key to your project. To do this:

    • Include the API key in a <meta-data> element:

      <meta-data
         android:name="com.google.android.ar.API_KEY"
         android:value="<YOUR_API_KEY>"/>
      
      • Add the<meta-data> element to the <application> element in app/manifests/AndroidManifest.xml.

Try out the sample app

Build and run the helloarcloudanchor sample app to try out hosting and resolving Cloud Anchors.

  1. Make sure that developer options and debugging are enabled on your phone.

  2. Connect your phone to your development machine via USB.

  3. In Android Studio, click Run. Select your device as the deployment target and click OK.

    The sample app launches on your phone and ARCore starts detecting planes in front of your camera.

  4. Once planes are detected, tap your phone screen to place an anchor on a plane.

  5. Tap the HOST button to host the anchor.

    A host request is sent to the Google Cloud Anchor service. The host request includes data representing the anchor's position relative to the visual features near it. A successful host request establishes a Cloud Anchors here and assigns it a Cloud Anchors ID.

    The app displays a room code after the hosting request succeeds. You can use the code to access previously hosted anchors for this room, using the same device or another device.

  6. Tap RESOLVE and enter a previously returned room code to access hosted anchors for this room.

    A resolve request is sent to the Google ARCore Cloud Anchor API, returning the IDs of anchors currently hosted in the room. The sample app uses these IDs to render 3D objects attached to the hosted anchors.

Next Steps

Start using Cloud Anchors in your own apps. To learn more, see:

Send feedback about...