Gradle is a build system that automates a number of build processes and prevents many common build errors. Unity uses Gradle for all Android builds. You can either build the output package (.apk, .aab) in Unity, or export a Gradle project from Unity, and then build it with an external tool such as Android Studio.
For more information about:
The following table shows compatibility between Gradle version and Unity version.
Unity version | Gradle version |
---|---|
2022.2 | 7.2 |
2022.1 2021.3 2021.2 2021.1 starting from 2021.1.16f1 2020.3 starting from 2020.3.15f1 |
6.1.1 |
2021.1 up to and including 2021.1.15f1 2020.1, 2020.2, 2020.3 up to and including 2020.3.14f1 |
5.6.4 |
2019.4 | 5.1.1 |
If you want to use a custom Gradle or Android Gradle plugin version, it’s important to know the version compatibility between Gradle and the Android Gradle plugin. For information on this, see Update Gradle.
Gradle project files configure different aspects of your application, such as which modules to include and how to build them.
The following table lists the Gradle project files that exist for Unity projects and describes the purpose of each one.
Gradle project file | Purpose |
---|---|
Main Manifest | This file contains important metadata about your Android application. For more information about the responsibilities of the Main/Unity Library Manifest see Unity Library Manifest. |
Unity Launcher Manifest | This file contains important metadata about your Android application’s launcher. For more information about the responsibilities of the Unity Launcher Manifest see Unity Launcher Manifest. |
Main Gradle | This file contains information on how to build your Android application as a library. |
Launcher Gradle | This file contains instructions on how to build your Android application. |
Base Gradle | This file contains configuration that is shared between all other templates and Gradle projects. |
Gradle Properties | This file contains configuration settings for the Gradle build environment. This includes:- The JVM (Java Virtual Machine) memory configuration.- A property to allow Gradle to build using multiple JVMs.- A property for choosing the tool to do the minification.- A property to not compress native libs when building an app bundle. |
Proguard | This file contains configuration settings for the minification process. If minification removes some Java code which should be kept, you should add a rule to keep that code in this file. |
If you export your Unity project as a Gradle project, Unity creates a Gradle project with two modules:
File | Description |
---|---|
build.gradle | The base Gradle file that affects all modules in the Gradle project. It specifies which plugin versions to use in this Gradle project. One of these plugins is Android Gradle Plugin. To influence the contents of this file, provide a custom Base Gradle Template. |
gradle.properties | A standard Gradle project file that configures how to build the application. Unity also adds the names of assets inside the Streaming Assets directory and specifies that these assets should be in the final application and Gradle shouldn’t compress them. To influence the contents of this file, provide a custom Gradle Properties Template. For information on the properties this file can contain, see Gradle property files. |
launcher | A directory that contains the launcher module and everything related to it. |
build.gradle | A standard Gradle project build.gradle file that describes how to build the launcher module and includes a list of dependencies to include in the build. In Unity, the launcher module depends on the unityLibrary module which means unityLibrary is built and included in the final result when building the launcher module. To influence the contents of this file, provide a custom Launcher Gradle Template. |
src | A standard Android Gradle project directory that contains the launcher module’s source code and resources. Unity places the source code and resources in the main subdirectory. |
main | A standard Android Gradle project directory that contains the launcher module’s source code and resources. Unity only supports the main source set. For more information about source sets, see Create source sets. |
AndroidManifest.xml | A standard Android Gradle project file that Unity merges into the final Android App Manifest. It contains settings specific to the launcher module. Important: If multiple manifest files specify different values for the same setting, the manifest merging process fails and you must fix it manually. You can specify rules for the manifest merger to automatically decide how to solve merge conflicts. For information on how to do this, see Manage manifest files. For information on how to influence the contents of this file, see the Override the Android App Manifest. |
jniLibs | A standard Android Gradle project directory that contains native code libraries that the launcher module uses. |
res | A standard Android Gradle project directory that contains resources to include in the final application. The resources are application icons, text that the application accesses at runtime, and application style descriptions. To specify the resources in this directory, set application icons and the project name in the Android Player Settings. |
local.properties | A standard Android Gradle project file that configures the environment of the build system. Unity specifies the path to SDK here so that by default, the exported Gradle project uses the same SDK that the Unity Editor used. NDK path used to be specified here with previous Gradle versions as well, but now Unity specifies it in the build.gradle files of launcher and unityLibrary modules. For information on the properties this file can contain, see Gradle property files. |
settings.gradle | A standard Android Gradle project file that specifies all of the modules that make up this Android Gradle project. In projects that Unity exports, this usually only specifies the launcher and unityLibrary modules. However, if the Unity project uses Play Asset Delivery, each asset pack is a separate module, so this file lists them too. The file also specifes locations which contain Gradle project plugins. The locations are a combination of online repositories and java plugins inside of this project. To influence the contents of this file, copy the settingsTemplate.gradle file in the PlaybackEngines/AndroidPlayer/Tools/GradleTemplates/ directory into Assets/Plugins/Android in your Unity project. You can then append your custom modifications to this file. |
unityLibrary | A directory that contains the unityLibrary module and everything related to it. |
build.gradle | A standard Gradle project build.gradle file that describes how to build the unityLibrary module and includes a list of dependencies to include in the build. In Unity, the unityLibrary module depends on all of the plug-insA set of code created outside of Unity that creates functionality in Unity. There are two kinds of plug-ins you can use in Unity: Managed plug-ins (managed .NET assemblies created with tools like Visual Studio) and Native plug-ins (platform-specific native code libraries). More info See in Glossary in the Unity project. To influence the contents of this file, provide a custom Main Gradle Template. |
libs | A common Android Gradle project directory that stores Android Archive (.aar) and Java Archive (.jar) plug-ins for the unityLibrary module. For exported Unity projects, this contains the unity-classes.jar as well as all .jar and .aar plugins in the Unity project. Note: This directory does not contain Android Library Projects plug-ins. Instead, Unity copies these into the Gradle project as separate modules. |
unity-classes.jar | A Unity-specific java plugin that contains java code that the Unity engine uses. |
proguard-unity.txt | A Unity-specific file that contains ProGuard configurations for Unity java code (code in unity-classes.jar plugin). Configurations are effective when Minification is enabled in Player settingsSettings that let you set various player-specific options for the final game built by Unity. More info See in Glossary (or if it is enabled by manually modifying gradle build files). |
src | A standard Android Gradle project directory that contains the unityLibrary module’s source code and resources. Unity places the source code and resources in the main subdirectory. |
main | A standard Android Gradle project directory that contains the unityLibrary module’s source code and resources. Unity only supports the main source set. For more information about source sets, see Create source sets. |
AndroidManifest.xml | A standard Android Gradle project file that Unity merges into the final Android App Manifest. It contains settings specific to the unityLibrary module. To influence the contents of this file, provide a custom Custom Main Manifest. |
assets | A standard Android Gradle directory that contains project assets. Unity places the Unity project’s resources in the bin subdirectory. |
bin | A standard Android Gradle project directory that Unity adds all of the Unity project’s resources to. |
java | A standard Android Gradle project directory that contains uncompiled java source files for the unityLibrary module. Unity only uses this directory to store the UnityPlayerActivity source file. For information on how to extend UnityPlayerActivity, see Extending the UnityPlayerActivity Java Code. |
jniLibs | A standard Android Gradle project directory that contains native code libraries that the unityLibrary module uses. Unity places the libil2cpp , libmain , and libunity Unity engine libraries in this directory. Unity also places any [Native (C++) plug-ins(AndroidNativePlugins) in this directory. |
res | A standard Android Gradle project directory that contains resources to include in the final application. For exported Unity projects, the res directory for the unityLibrary module only contains style descriptions that the unityLibrary module uses. |
proguard-user.txt | This is a Unity project specific file which contains ProGuard configurations for the project’s java code and 3rd party java plug-ins. Just like ProGuard-unity.txt Gradle uses it if you enable minification. To create this file, enable Custom Proguard File in the Android Player Settings. |
When you visit any website, it may store or retrieve information on your browser, mostly in the form of cookies. This information might be about you, your preferences or your device and is mostly used to make the site work as you expect it to. The information does not usually directly identify you, but it can give you a more personalized web experience. Because we respect your right to privacy, you can choose not to allow some types of cookies. Click on the different category headings to find out more and change our default settings. However, blocking some types of cookies may impact your experience of the site and the services we are able to offer.
More information
These cookies enable the website to provide enhanced functionality and personalisation. They may be set by us or by third party providers whose services we have added to our pages. If you do not allow these cookies then some or all of these services may not function properly.
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us to know which pages are the most and least popular and see how visitors move around the site. All information these cookies collect is aggregated and therefore anonymous. If you do not allow these cookies we will not know when you have visited our site, and will not be able to monitor its performance.
These cookies may be set through our site by our advertising partners. They may be used by those companies to build a profile of your interests and show you relevant adverts on other sites. They do not store directly personal information, but are based on uniquely identifying your browser and internet device. If you do not allow these cookies, you will experience less targeted advertising. Some 3rd party video providers do not allow video views without targeting cookies. If you are experiencing difficulty viewing a video, you will need to set your cookie preferences for targeting to yes if you wish to view videos from these providers. Unity does not control this.
These cookies are necessary for the website to function and cannot be switched off in our systems. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms. You can set your browser to block or alert you about these cookies, but some parts of the site will not then work. These cookies do not store any personally identifiable information.