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:
- 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:
- 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.
- 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.
- Open your project's build.gradle file:
- Make sure it includes Google's Maven repository (it should be there; if not, add it):
allprojects {
repositories {
google()
- Open your app's build.gradle file:
- Now, add the latest ARCore library as a dependency (1.13.0, in this book):
dependencies {
...
implementation 'com.google.ar:core:1.13.0'
...
}
- 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:
Now that we have ARCore enabled, let's introduce Sceneform.