Stay organized with collections
Save and categorize content based on your preferences.
When building an Android project that targets Android 12 (SDK level 31), you may encounter the following error:
Could not determine the dependencies of task ':launcher:compileDebugJavaWithJavac'.
> Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.
> Configure project :launcher
WARNING: The option 'android.enableR8' is deprecated and should not be used anymore.
It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8.
Build-tool 31.0.0 is missing DX at <android-sdk-path>/sdk/build-tools/31.0.0/dx
File ~/.android/repositories.cfg could not be loaded.
Build-tool 31.0.0 is missing DX at <android-sdk-path>/sdk/build-tools/31.0.0/dx
This is caused by an incompatibility between Android Build Tools version 31.0.0 and the Unity build system. As of Android Build Tools version 31.0.0, DX has been removed in favor of D8, leading to breakage in Unity builds for Android.
This error may be triggered in the following scenarios:
Upgrading to ARCore Extensions for Unity's AR Foundation version 1.26,
Targeting Android SDK level 31 in any Unity project, regardless of ARCore Extensions version,
Targeting Android SDK level 30 in any Unity project while Build Tools version 31.0.0 is installed, regardless of ARCore Extensions version.
Workaround
We are working with Unity to resolve this incompatibility. In the meantime, follow instructions to build a project that targets Android 12:
In Project Settings > Player > Android > Publishing Settings >
Build, select both:
Custom Main Gradle Template,
Custom Launcher Gradle Template.
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
Then modify compileSdkVersion and buildToolsVersion as follows:
buildToolsVersion '30.0.3'
When building, Unity will download Build-Tools version 30.0.3 and use it to build your project while maintaining the selected targetSdkVersion.
Create custom Gradle builds
On Unity versions 2019.4, 2020.1, and 2020.2, which are built with older versions, you will need to set a custom Gradle build to Gradle version 6.1.1 or later. You will also need Android Gradle Plugin 4.0.1 or later.
Apps targeting SDK 31 require Gradle Version 6.1.1 or later.
Go to Preferences > External Tools > Android > Gradle, and set the custom Gradle build to Gradle 6.1.1 or later. See Gradle build tool for downloads.
Apply the following changes to both generated files:
Assets/Plugins/Android/mainTemplate.gradle
Assets/Plugins/Android/launcherTemplate.gradle
buildscript{repositories{google()jcenter()}dependencies{// Must be Android Gradle Plugin 4.0.1 or later. For a list of// compatible Gradle versions refer to:// https://developer.android.com/studio/releases/gradle-pluginclasspath'com.android.tools.build:gradle:4.0.1'}}allprojects{repositories{google()jcenter()flatDir{dirs'libs'}}}
Apply changes for apps targeting Android 12
If your app targets Android 12, then you must explicitly declare the android:exported attribute. For all changes in Android 12, see Behavior changes in Android 12.
In Project Settings > Player > Android > Publishing Settings >
Build, select Custom Main Manifest.
Apply the following changes to Assets/Plugins/Android/AndroidManifest.xml:
If present, remove the following comment at the top of the file:
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-10-31 UTC."],[[["\u003cp\u003eBuilding Android projects targeting Android 12 with Unity may result in errors due to incompatibility with Build Tools version 31.0.0.\u003c/p\u003e\n"],["\u003cp\u003eAs a workaround, use Build Tools version 30.0.3 by enabling custom Gradle templates and modifying the \u003ccode\u003ebuildToolsVersion\u003c/code\u003e in the generated files.\u003c/p\u003e\n"],["\u003cp\u003eProjects using Unity versions 2019.4, 2020.1, or 2020.2 require custom Gradle builds with Gradle 6.1.1 or later and Android Gradle Plugin 4.0.1 or later.\u003c/p\u003e\n"],["\u003cp\u003eApps targeting Android 12 need an explicit \u003ccode\u003eandroid:exported\u003c/code\u003e attribute in the AndroidManifest.xml file's \u003ccode\u003e<activity>\u003c/code\u003e tag.\u003c/p\u003e\n"]]],[],null,["When building an Android project that targets Android 12 (SDK level 31), you may encounter the following error: \n\n Could not determine the dependencies of task ':launcher:compileDebugJavaWithJavac'.\n \u003e Installed Build Tools revision 31.0.0 is corrupted. Remove and install again using the SDK Manager.\n \u003e Configure project :launcher\n WARNING: The option 'android.enableR8' is deprecated and should not be used anymore.\n It will be removed in a future version of the Android Gradle plugin, and will no longer allow you to disable R8.\n Build-tool 31.0.0 is missing DX at \u003candroid-sdk-path\u003e/sdk/build-tools/31.0.0/dx\n File ~/.android/repositories.cfg could not be loaded.\n Build-tool 31.0.0 is missing DX at \u003candroid-sdk-path\u003e/sdk/build-tools/31.0.0/dx\n\nThis is caused by an incompatibility between Android Build Tools version 31.0.0 and the Unity build system. As of Android Build Tools version 31.0.0, [DX has been removed in favor of D8](https://android-developers.googleblog.com/2020/02/the-path-to-dx-deprecation.html), leading to breakage in Unity builds for Android.\n\nThis error may be triggered in the following scenarios:\n\n- Upgrading to ARCore Extensions for Unity's AR Foundation version 1.26,\n- Targeting Android SDK level 31 in any Unity project, regardless of ARCore Extensions version,\n- Targeting Android SDK level 30 in any Unity project while Build Tools version 31.0.0 is installed, regardless of ARCore Extensions version.\n\nWorkaround\n\nWe are working with Unity to resolve this incompatibility. In the meantime, follow instructions to build a project that targets Android 12:\n\n1. In **Project Settings \\\u003e Player \\\u003e Android \\\u003e Publishing Settings \\\u003e\n Build**, select both:\n\n 1. **Custom Main Gradle Template**,\n 2. **Custom Launcher Gradle Template**.\n\n2. Apply the following changes to both generated files:\n\n - `Assets/Plugins/Android/mainTemplate.gradle`\n - `Assets/Plugins/Android/launcherTemplate.gradle`\n\n If present, remove the following comment at the top of the file: \n\n // GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN\n\n Then modify `compileSdkVersion` and `buildToolsVersion` as follows: \n\n buildToolsVersion '30.0.3'\n\nWhen building, Unity will download Build-Tools version 30.0.3 and use it to build your project while maintaining the selected `targetSdkVersion`.\n\nCreate custom Gradle builds\n\nOn Unity versions **2019.4** , **2020.1** , and **2020.2** , which are built with older versions, you will need to set a custom Gradle build to **Gradle version 6.1.1 or later** . You will also need **Android Gradle Plugin 4.0.1 or later**.\n| **Note:** Unity versions **2020.3.15** and **2021.1.16** now have built-in Gradle builds. Lower versions will still need custom Gradle builds.\n\nApps targeting SDK 31 require **Gradle Version 6.1.1 or later**.\n\n1. Go to **Preferences \\\u003e External Tools \\\u003e Android \\\u003e Gradle** , and set the custom Gradle build to **Gradle 6.1.1 or later** . See [Gradle build tool](https://gradle.org/releases/) for downloads.\n2. Apply the following changes to both generated files:\n\n - `Assets/Plugins/Android/mainTemplate.gradle`\n - `Assets/Plugins/Android/launcherTemplate.gradle`\n\n buildscript {\n repositories {\n google()\n jcenter()\n }\n dependencies {\n // Must be Android Gradle Plugin 4.0.1 or later. For a list of\n // compatible Gradle versions refer to:\n // https://developer.android.com/studio/releases/gradle-plugin\n classpath 'com.android.tools.build:gradle:4.0.1'\n }\n }\n\n allprojects {\n repositories {\n google()\n jcenter()\n flatDir {\n dirs 'libs'\n }\n }\n }\n\nApply changes for apps targeting Android 12\n\nIf your app targets Android 12, then you must explicitly declare the `android:exported` attribute. For all changes in Android 12, see [Behavior changes in Android 12](https://developer.android.com/about/versions/12/behavior-changes-12#exported).\n\n1. In **Project Settings \\\u003e Player \\\u003e Android \\\u003e Publishing Settings \\\u003e\n Build** , select **Custom Main Manifest**.\n\n2. Apply the following changes to `Assets/Plugins/Android/AndroidManifest.xml`:\n\n 1. If present, remove the following comment at the top of the file:\n\n \u003c!-- GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN--\u003e\n\n 2. Add the [`android:exported` attribute](https://developer.android.com/about/versions/12/behavior-changes-12#exported) to the `\u003cactivity\u003e` tag:\n\n \u003capplication\u003e\n \u003cactivity android:name=\"com.unity3d.player.UnityPlayerActivity\"\n android:theme=\"@style/UnityThemeSelector\"\n android:exported=\"true\"\u003e\n \u003cintent-filter\u003e\n \u003caction android:name=\"android.intent.action.MAIN\" /\u003e\n \u003ccategory android:name=\"android.intent.category.LAUNCHER\" /\u003e\n \u003c/intent-filter\u003e\n \u003cmeta-data android:name=\"unityplayer.UnityActivity\" android:value=\"true\" /\u003e\n \u003c/activity\u003e\n \u003c/application\u003e"]]