Enabling ARCore

In an AR project, ARCore can be set as optional or required. The former can work as a regular app on devices that don't support ARCore, while the latter will only appear in the Google Play Store to devices that support ARCore. Our app is a full AR application, so we will select the second option. To achieve this we have to modify some of the project files. Let's get started:

  1. In the project window, unfold app and inside the manifests folder, open the AndroidManifest.xml file, as shown in the following screenshot. If you want to open the manifest externally you can find the file in app/src/main folder:

AndroidManifest.xml in the project
  1. Add the following lines before the <application> tag:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera.ar" />

The first line is necessary in both cases (ARCore is optional and required) since it's the one giving permission to open the camera. The second line indicates the use of ARCore and is the one ensuring that only devices that support ARCore will have access to the app.

  1. Now, add the following line inside <application>:
<application
...
<meta-data android:name="com.google.ar.core" android:value="required" />
</application>

This line sets ARCore as required and will make the Google Play Store download and install ARCore (if it's not already installed) when the app is installed.

  1. Open your project's build.gradle file:

The project's build.gradle file in the Project window
  1. Make sure it includes Google's Maven repository (it should be there; if not, add it):
allprojects {
repositories {
google()
  1. Open your app's build.gradle file:

The app's build.gradle file in the Project window
  1. Now, add the latest ARCore library as a dependency (1.13.0, in this book):
dependencies {
...
implementation 'com.google.ar:core:1.13.0'
...
}
  1. Synchronize Gradle in order for these changes to be effective by clicking on Sync Now, which can be found at the top right of the screen:

Sync Now option to sync the project
If you intend to create an app that works both with and without AR, the steps to follow to enable ARCore will differ from the ones shown here. Please refer to https://developers.google.com/ar/develop/java/enable-arcore to see what changes you have to make. Also, take into account that you will have to check whether the mobile running the app supports ARCore. You can do this by looking at your code.

Now that we have ARCore enabled, let's introduce Sceneform.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.194.39