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 | Android Gradle plug-in version |
---|---|---|
2021.3.41f1+ | 7.5.1 | 7.4.2 |
2021.3.37f1 - 2021.3.40f1 | 6.7.1 | 4.2.2 |
2021.2.0b4 - 2021.3.36f1 | 6.1.1 | 4.0.1 |
Refer to the Gradle and Android Gradle plug-in versions for other Unity releases: 6000.0, 2022.3 and 2020.3
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, refer to 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, refer to 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, refer to 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 |
---|---|
launcher |
A directory that contains the launcher module and everything related to it. |
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, refer to Create source sets. |
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. |
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, refer to Manage manifest files. For information on how to influence the contents of this file, refer to Override the Android App Manifest. |
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. |
unityLibrary |
A directory that contains the unityLibrary module and everything related to it. |
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 and 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. |
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, refer to Create source sets. |
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, refer to 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 in this directory. |
jniStaticLibs
|
A standard Android project directory that contains baselib.a library that the unityLibrary module uses to create libil2cpp.so . |
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. |
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. |
symbols
|
A directory that Unity adds if you choose to generate symbol files for your application through the Create symbols.zip build setting. This directory includes files containing debug metadata and the symbol table section for Unity libraries. You can set the directory path in Android Studio to resolve function names during debugging. |
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. |
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). |
build.gradle |
The base Gradle file that affects all modules in the Gradle project. It specifies which Android Gradle Plugin version to use and locations of java plugins. The locations are a combination of online repositories and java plugins inside of this project. To influence the contents of this file, provide a custom Base Gradle Template. |
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. |
gradle.properties |
A standard Gradle project file that configures how to build the application. This file contains the following properties specific to Unity: • unityStreamingAssets: Indicates the names of assets inside the Streaming Assets directory. Unity specifies that these assets should be in the final application and Gradle shouldn’t compress them. • unityTemplateVersion: Specifies the version of the Gradle template file that Unity uses. If your project’s Gradle template version differs from the specified one, Unity throws an error to inform you to update your Gradle files and build your project in an empty folder. • unityProjectPath: Specifies the path to your Unity project. For information on the Gradle properties this file can contain, refer to Gradle property files. To influence the contents of this file, provide a custom Gradle Properties Template. |
local.properties |
A standard Android Gradle project file that configures the environment of the build system. Unity specifies the path to SDK and NDK here so that by default, the exported Gradle project uses the same SDK and NDK that the Unity Editor used. For information on the properties this file can contain, refer to 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. 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. |