Google is committed to advancing racial equity for Black communities. See how.

Build for Android 11 with Unity

To support Android 11 (API level 30), the package visibility <queries> element was added to both ARCore Extensions for AR Foundation and the ARCore SDK for Unity (1.19 or later). When using these versions of ARCore with Unity 2018.4 or later, the <queries> element requires Gradle version 5.6.4 or later.

In most cases, using the Android Gradle plugin version 3.6.0 is sufficient. To confirm compatibility between the Android Gradle plugin and the Gradle version you are using, consult the Android Gradle plugin compatibility table.

Unity gradle support

Instructions for supported versions of Unity are listed in the following sections. Versions of Unity that do not support customization of Gradle are unable to target Android 11 (API level 30) (targetSdkVersion 30) directly from a Unity build.

For more information see these articles:

Unity 2020.1 or later

These versions are built with Gradle 5.6.4 or later and Gradle plugin 3.6.0 or later. No action is required.

Unity 2019.3 and 2019.4

  1. Go to Preferences > External Tools > Android > Gradle, and set the custom Gradle to Gradle 5.6.4 or later. See Gradle build tool for downloads.

    A screenshot of the External Tools, Android pane showing a manually
specified Gradle path.

  2. Go to Project Settings > Player > Android tab > Publishing Settings > Build, and select both:

    1. Custom Main Gradle Template
    2. Custom Launcher Gradle Template.

    A screenshot showing the Publishing Settings, Build pane with both Gradle
Template options selected

  3. Apply the following changes to both generated files:

    • Assets/Plugins/Android/mainTemplate.gradle
    • Assets/Plugins/Android/launcherTemplate.gradle

    If present, remove the following comment at the top of the file:

    // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
    

    Insert the following lines at the top of the file:

    buildscript {
        repositories {
            google()
            jcenter()
        }
        dependencies {
            // Must be Android Gradle Plugin 3.6.0 or later. For a list of
            // compatible Gradle versions refer to:
            // https://developer.android.com/studio/releases/gradle-plugin
            classpath 'com.android.tools.build:gradle:3.6.0'
        }
    }
    
    allprojects {
       repositories {
          google()
          jcenter()
          flatDir {
            dirs 'libs'
          }
       }
    }
    

2019.1 and 2019.2

  1. Go to Preferences > External Tools > Android > Gradle Installed with Unity. Clear the option, and specify a custom version of 5.6.4 or later. See Gradle build tool for downloads.

    A screenshot of the External Tools, Android pane showing a manually
specified Gradle path.

  2. Go to Project Settings > Player > Android Tab > Publishing Settings > Build, and select Custom Gradle Template.

    A screenshot of the Publishing Settings, Build pane showing Custom Gradle
Template selected.

  3. Edit the generated file Assets/Plugins/Android/mainTemplate.gradle, and set the dependency com.android.tools.build:gradle to 3.6.0 or later based on the Gradle version you use.

    buildscript {
        dependencies {
            // Must be Android Gradle Plugin 3.6.0 or later. For a list of
            // compatible Gradle versions refer to:
            // https://developer.android.com/studio/releases/gradle-plugin
            classpath 'com.android.tools.build:gradle:3.6.0'
        }
    }
    

Unity 2018.4

  1. Go to Build Settings > Android, and set Build System to Gradle to use the custom Gradle version.

    A screenshot of the Unity platform selection window which highlights
selecting Gradle as the build system from a drop down selection element.

  2. Go to Preferences > External Tools > Android > Gradle Installed with Unity. Clear the option, and specify a custom version of 5.6.4 or later. See Gradle build tool for downloads.

    A screenshot of the External Tools, Android pane showing a manually
specified Gradle path.

  3. Go to Project Settings > Player > Android tab > Publishing Settings > Build, and select Custom Gradle Template.

    A screenshot of the Publishing Settings, Build pane showing Custom Gradle
Template selected.

  4. Edit the generated file Assets/Plugins/Android/mainTemplate.gradle, and set the dependency com.android.tools.build:gradle to 3.6.0 or later based on the Gradle version you use.

    buildscript {
        dependencies {
            // Must be Android Gradle Plugin 3.6.0 or later. For a list of
            // compatible Gradle versions refer to:
            // https://developer.android.com/studio/releases/gradle-plugin
            classpath 'com.android.tools.build:gradle:3.6.0'
        }
    }
    

Unity 2018.3 or earlier, including 2017

Gradle customizations are not supported on these versions of Unity and are not compatible with the necessary changes to support Android 11 (API level 30).

The ARCore SDK for Unity strips the Android 11 (API level 30) support on those versions, so your app still works seamlessly on Android 10 (API level 29) and earlier.