Enable AR to use augmented reality features in your new or existing app.
Configure your app to be AR Required or AR Optional
To save space on individual devices, all AR features are stored in an app called Google Play Services for AR that is updated separately by the Play Store. Android apps that use AR features communicate with Google Play Services for AR using the ARCore SDK. An app that supports AR features can be configured in two ways: AR Required and AR Optional. This designation determines how the app interacts with the Google Play Services for AR app.
An AR Required app cannot function without ARCore. It requires an ARCore supported device that has installed Google Play Services for AR.
- The Google Play Store will only make AR Required apps available on devices that support ARCore.
- When users install an AR Required app, the Google Play Store will automatically install Google Play Services for AR on their device. However, your app must still perform additional runtime checks in case Google Play Services for AR is out of date or has been manually uninstalled.
An AR Optional app uses ARCore to enhance existing functionality. It has optional AR features which are only activated on ARCore supported devices that have installed Google Play Services for AR.
- AR Optional apps can be installed and run on devices that don’t support ARCore.
- When users install an AR Optional app, the Google Play Store will not automatically install Google Play Services for AR on the device.
AR Required | AR Optional | |
---|---|---|
AR Feature usage | Your app needs ARCore for basic functionality. | ARCore augments your app's functionality. Your app can run without ARCore support. |
Play Store visibility | Your app is only listed in the Play Store on devices that support ARCore. | Your app follows normal listing procedures. |
Google Play Services for AR installation method | The Play Store installs Google Play Services for AR alongside your app. | Your app uses
ArCoreApk.requestInstall()
to download and install ARCore. |
Android minSdkVersion requirements |
Android 7.0 (API Level 24) | Android 4.4 (API Level 19), though running any AR functionality requires at least Android 7.0 (API Level 24) |
Must use ArCoreApk.checkAvailability() or ArCoreApk.checkAvailabilityAsync() to check ARCore support and install status
|
||
Must use
ArCoreApk.requestInstall()
to install Google Play Services for AR |
To make your app AR Required or AR Optional, update your AndroidManifest.xml
to include the following entries:
AR Required
<uses-permission android:name="android.permission.CAMERA" />
<!-- Limits app visibility in the Google Play Store to ARCore supported devices
(https://developers.google.com/ar/devices). -->
<uses-feature android:name="android.hardware.camera.ar" />
<application …>
…
<!-- "AR Required" app, requires "Google Play Services for AR" (ARCore)
to be installed, as the app does not include any non-AR features. -->
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>
AR Optional
<uses-permission android:name="android.permission.CAMERA" />
<!-- If your app was previously AR Required, don't forget to remove the
`<uses-feature android:name="android.hardware.camera.ar" />` entry, as
this would limit app visibility in the Google Play Store to only
ARCore supported devices. -->
<application …>
…
<!-- "AR Optional" app, contains non-AR features that can be used when
"Google Play Services for AR" (ARCore) is not available. -->
<meta-data android:name="com.google.ar.core" android:value="optional" />
</application>
Then, modify your app's build.gradle
to specify a minSdkVersion
of at least 24
:
android {
defaultConfig {
…
minSdkVersion 24
}
}
Add build dependencies
To add ARCore to your Android Studio project, do the following:
Make sure your project's
build.gradle
file includes Google's Maven repository.allprojects { repositories { google() … } }
Add the latest ARCore library as a dependency in your app's
build.gradle
file.dependencies { … implementation 'com.google.ar:core:1.33.0' }
Perform runtime checks
During runtime, perform the following to ensure that AR features on your app run smoothly.
Check if ARCore is supported
Both AR Required and AR Optional apps should useArCoreApk.checkAvailability()
or ArCoreApk.checkAvailabilityAsync()
to determine if the current device supports ARCore. On devices that do not support ARCore, apps should disable AR-related functionality and hide associated UI elements.
Kotlin
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// Enable AR-related functionality on ARCore supported devices only.
maybeEnableArButton()
…
}
fun maybeEnableArButton() {
ArCoreApk.getInstance().checkAvailabilityAsync(this) { availability ->
if (availability.isSupported) {
mArButton.visibility = View.VISIBLE
mArButton.isEnabled = true
} else { // The device is unsupported or unknown.
mArButton.visibility = View.INVISIBLE
mArButton.isEnabled = false
}
}
}
Java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Enable AR-related functionality on ARCore supported devices only.
maybeEnableArButton();
…
}
void maybeEnableArButton() {
ArCoreApk.getInstance().checkAvailabilityAsync(this, availability -> {
if (availability.isSupported()) {
mArButton.setVisibility(View.VISIBLE);
mArButton.setEnabled(true);
} else { // The device is unsupported or unknown.
mArButton.setVisibility(View.INVISIBLE);
mArButton.setEnabled(false);
}
});
}
ArCoreApk.checkAvailability()
or ArCoreApk.checkAvailabilityAsync()
to check for ARCore support ensures a consistent experience.
ArCoreApk.checkAvailability()
may need to query network resources to determine whether the device supports ARCore. During this time, it will return UNKNOWN_CHECKING
. To reduce the perceived latency and pop-in, apps should call ArCoreApk.checkAvailability()
once early in its life cycle to initiate the query, ignoring the returned value. This way, a cached result will be available immediately when an AR-entering UI element might be displayed.
Check if Google Play Services for AR is installed
Both AR Required and AR Optional apps must use
ArCoreApk.requestInstall()
before creating an ARCore session to check whether a compatible version of Google Play Services for AR is (still) installed and to ensure that all required ARCore device profile data has been downloaded.
Kotlin
// requestInstall(Activity, true) will triggers installation of
// Google Play Services for AR if necessary.
var mUserRequestedInstall = true
override fun onResume() {
super.onResume()
// Check camera permission.
…
// Ensure that Google Play Services for AR and ARCore device profile data are
// installed and up to date.
try {
if (mSession == null) {
when (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) {
ArCoreApk.InstallStatus.INSTALLED -> {
// Success: Safe to create the AR session.
mSession = Session(this)
}
ArCoreApk.InstallStatus.INSTALL_REQUESTED -> {
// When this method returns `INSTALL_REQUESTED`:
// 1. ARCore pauses this activity.
// 2. ARCore prompts the user to install or update Google Play
// Services for AR (market://details?id=com.google.ar.core).
// 3. ARCore downloads the latest device profile data.
// 4. ARCore resumes this activity. The next invocation of
// requestInstall() will either return `INSTALLED` or throw an
// exception if the installation or update did not succeed.
mUserRequestedInstall = false
return
}
}
}
} catch (e: UnavailableUserDeclinedInstallationException) {
// Display an appropriate message to the user and return gracefully.
Toast.makeText(this, "TODO: handle exception " + e, Toast.LENGTH_LONG)
.show()
return
} catch (…) {
…
return // mSession remains null, since session creation has failed.
}
…
}
Java
// requestInstall(Activity, true) will trigger installation of
// Google Play Services for AR if necessary.
private boolean mUserRequestedInstall = true;
@Override
protected void onResume() {
super.onResume();
// Check camera permission.
…
// Ensure that Google Play Services for AR and ARCore device profile data are
// installed and up to date.
try {
if (mSession == null) {
switch (ArCoreApk.getInstance().requestInstall(this, mUserRequestedInstall)) {
case INSTALLED:
// Success: Safe to create the AR session.
mSession = new Session(this);
break;
case INSTALL_REQUESTED:
// When this method returns `INSTALL_REQUESTED`:
// 1. ARCore pauses this activity.
// 2. ARCore prompts the user to install or update Google Play
// Services for AR (market://details?id=com.google.ar.core).
// 3. ARCore downloads the latest device profile data.
// 4. ARCore resumes this activity. The next invocation of
// requestInstall() will either return `INSTALLED` or throw an
// exception if the installation or update did not succeed.
mUserRequestedInstall = false;
return;
}
}
} catch (UnavailableUserDeclinedInstallationException e) {
// Display an appropriate message to the user and return gracefully.
Toast.makeText(this, "TODO: handle exception " + e, Toast.LENGTH_LONG)
.show();
return;
} catch (…) {
…
return; // mSession remains null, since session creation has failed.
}
…
}
Request camera permission
Both AR Optional and AR Required apps must ensure that the camera permission has been granted before creating an AR Session.
Kotlin
override fun onResume() {
super.onResume()
// ARCore requires camera permission to operate.
if (!CameraPermissionHelper.hasCameraPermission(this)) {
CameraPermissionHelper.requestCameraPermission(this)
return
}
…
}
Java
@Override
protected void onResume() {
super.onResume();
// ARCore requires camera permission to operate.
if (!CameraPermissionHelper.hasCameraPermission(this)) {
CameraPermissionHelper.requestCameraPermission(this);
return;
}
…
}
Your AR activity must also implement onRequestPermissionsResult()
.
Kotlin
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<String>,
results: IntArray
) {
super.onRequestPermissionsResult(requestCode, permissions, results)
if (!CameraPermissionHelper.hasCameraPermission(this)) {
Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
.show()
if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)) {
// Permission denied with checking "Do not ask again".
CameraPermissionHelper.launchPermissionSettings(this)
}
finish()
}
}
Java
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] results) {
super.onRequestPermissionsResult(requestCode, permissions, results);
if (!CameraPermissionHelper.hasCameraPermission(this)) {
Toast.makeText(this, "Camera permission is needed to run this application", Toast.LENGTH_LONG)
.show();
if (!CameraPermissionHelper.shouldShowRequestPermissionRationale(this)) {
// Permission denied with checking "Do not ask again".
CameraPermissionHelper.launchPermissionSettings(this);
}
finish();
}
}
Comply with User Privacy Requirements
To publish your app on the Play Store, make sure that your app complies with ARCore's User Privacy Requirements.
What’s next
- Learn how to configure an ARCore session.