使用 Unity 构建适用于 Android 11 的应用
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
为了支持 Android 11(API 级别 30),我们在适用于 AR Foundation 的 ARCore Extensions (1.19 或更高版本) 中添加了软件包可见性
<queries>
元素。使用这些版本的 ARCore 时,<queries>
元素需要 Gradle 5.6.4 或更高版本。
在大多数情况下,使用 Android Gradle 插件 3.6.0 版就足够了。如需确认 Android Gradle 插件与您使用的 Gradle 版本之间的兼容性,请参阅 Android Gradle 插件兼容性表。
对 Unity gradle 的支持
以下部分列出了适用于受支持 Unity 版本的说明。
如需了解详情,请参阅以下文章:
Unity 2021 及更高版本
所有版本的 Unity 2021 都支持以 Android 11 为目标平台。如需了解详细的版本信息,请参阅 Unity 2021 版 Gradle for Android 文档。总结:
Unity 2020
所有版本的 Unity 2020 都支持以 Android 11 为目标平台。如需了解详细的版本信息,请参阅 Unity 2020 版 Gradle for Android 文档。总结:
Unity 2019.4
在 Unity 中,打开 Unity Preferences > External Tools 并将自定义 Gradle 设置为 Gradle 5.6.4 或更高版本。请参阅 Gradle build 工具进行下载。

前往 Project Settings > Player > Android > Publishing Settings >
Build,然后同时选择以下两个选项:
- Custom Main Gradle Template
- Custom Launcher Gradle Template。

对两个生成的文件应用以下更改:
Assets/Plugins/Android/mainTemplate.gradle
Assets/Plugins/Android/launcherTemplate.gradle
移除文件顶部的以下注释(如果存在):
// GENERATED BY UNITY. REMOVE THIS COMMENT TO PREVENT OVERWRITING WHEN EXPORTING AGAIN
在文件顶部插入以下代码行:
buildscript {
repositories {
google()
mavenCentral()
}
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()
mavenCentral()
flatDir {
dirs 'libs'
}
}
}
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-26。
[null,null,["最后更新时间 (UTC):2025-07-26。"],[[["\u003cp\u003eTo support Android 11 with ARCore Extensions for AR Foundation, you need Gradle version 5.6.4 or later and usually Android Gradle plugin version 3.6.0.\u003c/p\u003e\n"],["\u003cp\u003eUnity 2021 and 2020 versions already include the necessary Gradle and plugin versions for Android 11 compatibility by default.\u003c/p\u003e\n"],["\u003cp\u003eFor Unity 2019.4, you need to manually update Gradle to 5.6.4 or later, enable custom Gradle templates, and modify these templates to use Android Gradle plugin 3.6.0.\u003c/p\u003e\n"],["\u003cp\u003eYou can find detailed information about compatible Gradle and Android Gradle plugin versions in the provided links, as well as guidance on Unity's Gradle support and Android build configuration.\u003c/p\u003e\n"]]],["To use ARCore Extensions for AR Foundation with Android 11, ensure Gradle version 5.6.4+ and Android Gradle plugin 3.6.0+ are utilized. Unity 2020 and 2021+ versions generally include compatible versions, requiring no action. Unity 2019.4 users need to manually set Gradle to 5.6.4+ and modify both `mainTemplate.gradle` and `launcherTemplate.gradle` files, adding buildscript and allprojects repositories, and setting the plugin to version 3.6.0.\n"],null,["# Build for Android 11 with Unity\n\nTo support Android 11 (API level 30), the [package visibility](https://developer.android.com/training/package-visibility)\n`\u003cqueries\u003e` element was added to ARCore Extensions for AR Foundation (1.19 or later).\nWhen using these versions of ARCore, the `\u003cqueries\u003e` element requires Gradle version\n5.6.4 or later.\n\nIn most cases, using the ***Android Gradle plugin* version 3.6.0** is\nsufficient. To confirm compatibility between the Android Gradle plugin and the\nGradle version you are using, consult the Android Gradle plugin\n[compatibility table](https://developer.android.com/studio/releases/gradle-plugin#updating-gradle).\n\nUnity gradle support\n--------------------\n\nInstructions for supported versions of Unity are listed in the following\nsections.\n\nFor more information see these articles:\n\n- Unity's [Gradle support](https://docs.unity3d.com/Manual/android-gradle-overview.html)\n- Android's [Configure Gradle Build](https://developer.android.com/studio/build)\n\nUnity 2021 and later\n--------------------\n\nAll versions of Unity 2021 support targeting Android 11. Refer to Unity's 2021\n[Gradle for Android](https://docs.unity3d.com/2021.2/Documentation/Manual/android-gradle-overview.html)\ndocumentation for detailed version information. To summarize:\n\n- Unity 2021.1 up to and including 2021.1.15f1 ship with Gradle 5.6.4 or later\n (and Gradle plugin 3.6.0 or later). No action is required.\n\n- Unity 2021.1.16f1 and later ship with Gradle 6.1.1 or later (and\n Gradle plugin 4.0.1 or later). No action is required.\n\nUnity 2020\n----------\n\nAll versions of Unity 2020 support targeting Android 11. Refer to Unity's 2020\n[Gradle for Android](https://docs.unity3d.com/2020.3/Documentation/Manual/android-gradle-overview.html)\ndocumentation for detailed version information. To summarize:\n\n- Unity 2020.1, 2020.2 and 2020.3 up to and including 2020.3.14f1 ship with\n Gradle 5.6.4 or later (and Gradle plugin 3.6.0 or later).\n No action is required.\n\n- Unity 2020.3.15f1 and later ship with Gradle 6.1.1 or later (and\n Gradle plugin 4.0.1 or later). No action is required.\n\nUnity 2019.4\n------------\n\n1. In Unity, open **[Unity Preferences](https://docs.unity3d.com/2019.4/Documentation/Manual/Preferences.html) \\\u003e [External Tools](https://docs.unity3d.com/2019.4/Documentation/Manual/Preferences.html#external-tools)** and set the custom\n **Gradle** to Gradle **5.6.4** or later. See\n [Gradle build tool](https://gradle.org/releases/) for downloads.\n\n2. Go to **Project Settings \\\u003e Player \\\u003e Android \\\u003e Publishing Settings \\\u003e\n Build**, and select both:\n\n 1. **Custom Main Gradle Template**\n 2. **Custom Launcher Gradle Template**.\n\n3. 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 Insert the following lines at the top of the file: \n\n buildscript {\n repositories {\n google()\n mavenCentral()\n }\n dependencies {\n // Must be Android Gradle Plugin 3.6.0 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:3.6.0'\n }\n }\n\n allprojects {\n repositories {\n google()\n mavenCentral()\n flatDir {\n dirs 'libs'\n }\n }\n }"]]