Gradle templates
Learn what Gradle templates are and how to use them to gain more control over the build process.
阅读时间3 分钟最后更新于 1 个月前
Gradle templates configure how to build an Android application using Gradle. Each Gradle template represents a single Gradle project. Gradle projects can include, and depend on, other Gradle projects.
Gradle template files
A Gradle template consists of the following files:
File | Location | Contains |
|---|---|---|
| In the exported project, | Configuration information that affects all modules in the final 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. |
| In the exported project, | Instructions on how to build the Android application. This includes bundling, signing, and whether to split the apk. It depends on the unityLibrary project and outputs either an .apk file or an app bundle. |
| In the exported project, | Instructions on how to build Unity as a Library. This outputs an .aar file. You can override the Unity template with a custom template in the Unity Editor. Refer to the Providing a custom Gradle build template section on this page for more details. |
| Varies | If an Android Library plug-in doesn't include a |
| In the exported project, | Specifies the names of modules that the Gradle build system should include when it builds the project. You can override the Unity template with a custom template in the Unity Editor. Refer to the Providing a custom Gradle build template section on this page for more details. |
| In the exported project, | Configures the Gradle build system and specifies properties such as the size of the Java virtual machine (JVM) heap |
To have more control over the Gradle project files that Unity produces, you can override Unity's default Gradle template files. For information on how to do this, refer to Modify Gradle project files with Gradle template files.
Modifying the exported Gradle project using C#
To modify the Gradle project after Unity assembles it, create a class that inherits from IPostGenerateGradleAndroidProject and override the OnPostGenerateGradleAndroidProject function. This function receives the path to the unityLibrary module as a parameter and you can use it to reach the application’s manifest and resources through C# scripting.