Version: 2023.2
Language : English
Android requirements and compatibility
Android App Manifest

Gradle for Android

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:

Version compatibility

The following table shows compatibility between Gradle version and Unity version.

Unity version Gradle version Android Gradle Plug-in version
2023.1, 2023.2 7.6 7.3.1
2022.2 7.2 7.1.2
2022.1
2021.3
2021.2
2021.1 starting from 2021.1.16f1
2020.3 starting from 2020.3.15f1
6.1.1 4.0.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 4.0.1
2019.4 5.1.1 3.4.0

If you want to use a custom Gradle or Android Gradle plug-in version, it’s important to know the version compatibility between Gradle and the Android Gradle plug-in. For information on this, refer to Update Gradle.

Gradle project files

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’s 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.
Gradle Settings This file contains declaration of artifact repositories to resolve external dependencies required for your application.
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.

Gradle project structure

If you export your Unity project as a Gradle project, Unity creates a Gradle project with two modules:

  • UnityLibrary module: Contains the Unity runtime and project data. This module is a library that you can integrate into any other Gradle project. You can use it to embed Unity into existing Android applications.
  • Launcher module: Contains the application’s name and all of its icons. This is a simple Android application module that launches Unity. You can replace it with your own application.
File Description
build.gradle The base Gradle file that affects all modules in the Gradle project. It specifies which plug-in versions to use in this Gradle project. One of these plug-ins is Android Gradle Plug-in.

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, refer to 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, refer to 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, refer to Manage manifest files.

For information on how to influence the contents of this file, refer to Modify Gradle project files.
      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, 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. The file also specifies locations which contain Gradle project plug-ins. The locations are a combination of online repositories and java plug-ins inside of this project.

To influence the contents of this file, provide a custom Gradle Settings Template.
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 and all .jar and .aar plug-ins in the Unity project.

Note: This directory doesn’t contain Android Library Projects plug-ins. Instead, Unity copies these into the Gradle project as separate modules.
    unity-classes.jar A Unity-specific java plug-in 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 plug-in). 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’s 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, refer to 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 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.
      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 third-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.
Android requirements and compatibility
Android App Manifest
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961