Version: 2022.2
言語: 日本語
Android requirements and compatibility
Android App Manifest

Android の Gradle

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
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

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 説明
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.

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.
ファイル 説明
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-ins 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 settings (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.
Android requirements and compatibility
Android App Manifest
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961