Version: 5.6
Android 2D Textures Overrides
Gradle troubleshooting

Gradle for Android

Gradle is an Android build system which automates a number of build processes. This automation means that many common build errors are less likely to occur. Most notably in Unity, it reduces the method reference count in DEX (Dalvik Executable format) files, meaning that you are less likely to come across DEX limit problems. However, due to the differences between Gradle and the default Unity Android build system, some existing projects may be hard to convert to Gradle.

You can either build the output package (APK) using the Gradle build system in Unity, or export the Gradle project and build it in an external tool (such as Android Studio).

To learn more, see Gradle’s resources on Getting Started with Gradle for Android Build.

Building with Gradle for Android

To build your Android build with Gradle in Unity:

  1. In the Unity Editor, open the Build Settings window (menu: File > Build Settings…)
  2. In the Platform list, select Android
  3. Set the Build System drop-down to Gradle (new), then click Build
Gradle build settings
Gradle build settings

Exporting the Gradle project

To export a Gradle project, follow the instructions above, but tick the Export Project option in the Build window before you click Build. When you click Build Unity generates a Gradle project in the specified directory rather than building the APK. Import this project into Android Studio to make additional modifications or to get full control of the build process.

See Android Studio’s documentation on configuring your build for more information about building an output package (APK).

Providing a custom build.gradle template

To use your own build.gradle file when building the APK from Unity, import your build.gradle file to Assets/Plugins/Android/mainTemplate.gradle. Note that the file might use some template variables like TARGETSDKVERSION. See the default mainTemplate.gradle file in the Unity installation for an example file.

Errors when building with Gradle

If an error occurs during building for Android using Gradle, Unity displays an error dialog box. Click Troubleshoot to open the Gradle troubleshooting Unity documentation in your system’s browser.

Unity’s Grade build error dialog box
Unity’s Grade build error dialog box

Android 2D Textures Overrides
Gradle troubleshooting
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961