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.
To build your Android build with Gradle in Unity:
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).
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.
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.
2017–05–22 Page published with no editorial review
New feature in 5.5
Did you find this page useful? Please give it a rating: