Version: 2023.2
Modify the Gradle project files for a Unity application
Modify Gradle project files with the Android Project Configuration Manager

Modify Gradle project files with Gradle template files

To have some control over the format and contents of Gradle project files, you can override Unity’s default templates with your own custom template. To do this:

  1. Go to Edit > Project Settings to open the Project Settings window.
  2. Select the Player tab, then open Android Player Settings:
  3. In the Publishing Settings section, enable the checkbox that corresponds to the Gradle project file type you want to create a custom template for. This creates a Gradle project template file and displays the path to the file.
  4. Modify the template file to control the final format and contents of the final Gradle project file.

To verify that your template modifications give the result that you expect, export your project and view the final Gradle project files in the resulting project.

Template variables

You can use the following variables in custom Gradle template files:

可变 描述
DEPS The list of project dependencies. This is the list of libraries that the project uses.
APIVERSION The API version to build for. Unity sets the and TARGETSDKVERSION to the same value (Target API Level in the Android Player Settings).
MINSDKVERSION The minimum API version that supports the application.
BUILDTOOLS The SDK build tools to use.
TARGETSDKVERSION The API version to target. Unity sets the and APIVERSION to the same value (Target API Level in the Android Player Settings).
APPLICATIONID Android Application ID. For example, com.mycompany.myapp.
MINIFY_DEBUG Indicates whether to minify debug builds.
PROGUARD_DEBUG Indicates whether to use ProGuard for minification in debug builds.
MINIFY_RELEASE Indicates whether to minify release builds.
PROGUARD_RELEASE Indicates whether to use ProGuard for minification in release builds.
USER_PROGUARD Specifies a custom ProGuard file to use for minification.
SIGN Complete the signingConfigs section if this build is signed.
SIGNCONFIG Indicates whether the build is signed. If this property is set to signingConfig.release, the build is signed.
DIR_GRADLEPROJECT Unity 创建 Gradle 项目的目录。
DIR_UNITYPROJECT The directory of your Unity project.
PLAY_ASSET_PACKS Specifies the asset packs to include in your application.
BUILTIN_NOCOMPRESS Specifies a default list of files extensions to not compress. The file extensions are: .unity3d, .ress, .resource, .obb, .bundle, .unityexp.

Custom settingsTemplate.gradle files can also contain the following variables:

可变 描述
INCLUDES The list of Android Library plug-ins to include in the Gradle project.

Custom gradleTemplate.properties files can also contain the following variables:

可变 描述
JVM_HEAP_SIZE The maximum size of the Java virtual machine (JVM) heap.
STREAMING_ASSETS The list of files in the Steaming Assets folder that Gradle shouldn’t compress.
ADDITIONAL_PROPERTIES Contains additional properties for the application. This includes:
• The Gradle template version.
• The path to the Unity project.
• If the application uses the Android App Bundle publishing format, a flag that indicates to keep native libraries compressed.
• If the application uses the GameActivity application entry point, a flag that indicates to use AndroidX.

其他资源

Modify the Gradle project files for a Unity application
Modify Gradle project files with the Android Project Configuration Manager