Version 1.2 of the ARCore SDK, as announced at Google I/O 2018, is now available. See the blog post for more information.

Enable ARCore

This page describes how to enable ARCore functionality in your Android Studio projects. To do this, you need to:

Add AR Required or AR Optional entries to manifest

There are two types of AR apps: AR Required and AR Optional.

AR Optional

AR Optional means that your app includes one or more AR features that are activated if the user's device supports ARCore. But the app can be installed and run on devices that don't support ARCore.

When users install an AR Optional app, the Play Store will not automatically install ARCore.

To declare your app as AR Optional, modify your app manifest to include the following entries:

  <uses-sdk android:minSdkVersion="{14 or higher}" />
  ...

  <application>
    ...
        <meta-data android:name="com.google.ar.core" android:value="optional" />
    ...

AR Required

AR Required means that your app is not usable without AR. The Play Store makes your app available only on devices that support ARCore. For more information, see Publishing AR Apps in the Play Store.

When users install an AR Required app, the Play Store will automatically install ARCore. However, your app must still perform additional runtime checks, in case the user has uninstalled ARCore.

To declare your app AR Required, modify your app manifest to include the following entries:

<uses-sdk android:minSdkVersion="{24 or higher}" />

  ...
  <uses-feature android:name="android.hardware.camera.ar" android:required="true" />

  <application>
    ...
        <meta-data android:name="com.google.ar.core" android:value="required" />
    ...

Add build dependencies

Perform these steps:

  • Make sure your project's build.gradle file includes Google's Maven repository:

    allprojects {
    repositories {
        google()
            ...
    
  • Add the ARCore library as a dependency in your app's build.gradle file.

    dependencies {
        // ARCore library
        implementation 'com.google.ar:core:1.2.0'
    }
    
  • (Optional) Add the Sceneform library to your app's build.gradle file:

    // Sceneform libraries use language constructs from Java 8.
    // Add these compile options if targeting a min API level less than 26.
    android {
        compileOptions {
            sourceCompatibility 1.8
            targetCompatibility 1.8
        }
    }
    
    dependencies {
        implementation "com.google.ar.sceneform:core:1.0.0"
        implementation "com.google.ar.sceneform.ux:sceneform-ux:1.0.0"
    }
    

Perform runtime checks

Check whether ARCore is supported (AR Optional apps only)

AR optional apps can use ArCoreApk.checkAvailability() to determine if the current device supports ARCore. On a device that does not support ARCore, apps should disable AR-related functionality and hide associated UI elements.

void maybeEnableArButton() {
  // Likely called from Activity.onCreate() of an activity with AR buttons.
  ArCoreApk.Availability availability = ArCoreApk.getInstance().checkAvailability(this);
  if (availability.isTransient()) {
    // re-query at 5Hz while we check compatibility.
    new Handler().postDelayed(new Runnable() {
      @Override
      public void run() {
        maybeEnableArButton();
      }
    }, 200);
  }
  if (availability.isSupported()) {
    mArButton.setVisibility(View.VISIBLE);
    mArButton.setEnabled(true);
    // indicator on the button.
  } else { // unsupported or unknown
    mArButton.setVisibility(View.INVISIBLE);
    mArButton.setEnabled(false);
  }
}

This flowchart illustrates the logic in the preceding code sample:

Then, when the user wants to use an AR feature, your app should ensure that ARCore is installed. An easy way to do this is by launching an activity that follows the AR Required pattern described above.

Check whether ARCore is installed

AR Required and AR Optional apps must call ArCoreApk.requestInstall() before creating an ARCore session. requestInstall() checks whether a compatible version of ARCore is installed (it might be out of date or have been manually removed by the user) and will prompt the user to install ARCore if it is not present.

// Set to true ensures requestInstall() triggers installation if necessary.
private boolean mUserRequestedInstall = true;

// in onResume:
try {
  if (mSession == null) {
    switch (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) {
      case INSTALLED:
        mSession = new Session(this);
        // Success.
        break;
      case INSTALL_REQUESTED:
        // Ensures next invocation of requestInstall() will either return
        // INSTALLED or throw an exception.
        mUserRequestedInstall = false;
        return;
    }
  }
} catch (UnavailableUserDeclinedInstallationException e) {
  // Display an appropriate message to the user and return gracefully.
  return;
} catch (...) {  // current catch statements
  ...
  return;  // mSession is still null
}

This flowchart illustrates the logic in the preceding code sample:

If requestInstall() returns INSTALL_REQUESTED, the current activity pauses and the user is prompted to install or update ARCore. The activity's onResume() executes again when the user returns to the activity.

Next steps

Read the code and comments in the sample app, as well as the Java API Reference.

Send feedback about...