Version: Unity 6 Preview (6000.0)
Language : English
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 GradleAn Android build system that automates several build processes. This automation means that many common build errors are less likely to occur. More info
See in Glossary
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.

Note: If there is a discrepancy between the values set in the Android Player settingsSettings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary
and the template file, Unity displays a warning message, and Player settings take precedence.

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:

Variable Description
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 APIVERSION and TARGETSDK to the same value (Target API Level in the Android Player Settings).
MINSDK The minimum API version that supports the application.
BUILDTOOLS The SDK build tools to use.
TARGETSDK 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 The directory where Unity creates the Gradle project.
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.
NDKPATH Specifies the Android Native Development Kit (NDK) installation folder path set in the Android section of Preferences > External Tools.
IL2CPP_BUILD_SETUP The build script required to produce build artifacts related to IL2CPPA Unity-developed scripting back-end which you can use as an alternative to Mono when building projects for some platforms. More info
See in Glossary
, such as libil2cpp.so.
SOURCE_BUILD_SETUP Unity’s internal build script.
EXTERNAL_SOURCES The build script required to produce build artifacts such as, GameActivity and Swappy native libraries.

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

Variable Description
INCLUDES The list of Android Library 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
to include in the Gradle project.

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

Variable Description
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.

Additional resources

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