Что такое gradle в unity

Gradle for Android

Gradle is an Android build system that automates a number of build processes and prevents many common build errors. In Unity, Gradle reduces the method reference count in DEX (Dalvik Executable format) files, which means you are less likely to come across DEX limit problems.

Unity versionGradle version
2020.15.6.4
2018.4 starting from 2018.4.4f1
2019.1 starting from 2019.1.7f1, 2019.2, 2019.3, and 2019.4
5.1.1
2018.3, 2018.4 up to and including 2018.4.3f1
2019.1 up to and including 2019.1.6f1
4.6
2018.24.2.1
2018.14.0.1
2017.4, starting from 2017.4.174.6
2017.4 up to and including 2017.4.164.0.1
2017.1, 2017.22.14

To learn more about:

Building or exporting a Gradle project

To build a Gradle project, follow these steps:

Exported Gradle project structure

Unity 2019.3 and newer versions create a Gradle project with two modules:

build.gradle templates

Gradle templates describe and configure how to build your Android app with Gradle. Each Gradle template represents a singleGradle project. Gradle projects can include, and depend on other Gradle projects.

A Gradle template consists of the following files:

Customizing your Gradle build

You can provide a custom Gradle build template and select minification options in the Publishing Settings section of the Player Settings window.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unity

Providing a custom Gradle build template

You can use a custom build.gradle file for the unityLibrary module when you build the APK from Unity. This file contains specific build instructions specified in template variables. For a list of template variables, see the next section.

To use your own build.gradle file for the unityLibrary module, follow these steps:

Unity then generates a default mainTemplate.gradle file in your Project’s Assets/Plugins/Android/ folder. The path to the new file also appears under the Custom Gradle Template option in the Player Settings. Double-click the mainTemplate.gradle file in the Project view to open it in an external text editor.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unitymainTemplate.gradle file in the Project view for the unityLibrary module

You can also create your own settings.gradle file. To do this, you need to manually create a settingsTemplate.gradle file in your Project’s Assets/Plugins/Android/ folder. Unity uses this file to include your library projects. Unless you want to override this process, your file needs to contain this line:

Unity replaces this line with include directives to all of the Project’s libraries.

IPostGenerateGradleAndroidProject

IPostGenerateGradleAndroidProject returns the path to the unityLibrary module. This keeps everything similar to versions earlier than Unity 2019.3 and doesn’t require any further changes, which means Unity can reach the app’s manifest and resources in a consistent way across versions.

Template variables

The mainTemplate.gradle file can contain the following variables:

Variable:Description:
DEPSList of project dependencies
See in Glossary ; that is, the libraries that the Project uses.
APIVERSIONAPI version to build for (for example, 25).
MINSDKVERSIONMinimum API version (for example, 25).
BUILDTOOLSSDK Build tools used (for example, 25.0.1).
TARGETSDKVERSIONAPI version to target (for example, 25).
APPLICATIONIDAndroid Application ID (for example, com.mycompany.myapp).
MINIFY_DEBUGEnable minify for debug builds (true or false).
PROGUARD_DEBUGUse proguard for minification in debug builds (true or false.)
MINIFY_RELEASEEnable minify for release builds (true or false).
PROGUARD_RELEASEUse proguard for minification in release builds (true or false).
USER_PROGUARDCustom user proguard file (for example, proguard-user.txt ).
SIGNComplete the signingConfigs section if this build is signed.
SIGNCONFIGSet to signingConfig signingConfig.release if this build is signed.
DIR_GRADLEPROJECTThe directory where Unity creates the Gradle project.
DIR_UNITYPROJECTThe directory of your Unity Project.

Minification

You can use Proguard minification to shrink and optimize your app. To activate this option, follow these steps:

Note: Proguard might strip out important code that your app needs, so use these options carefully.

To generate a custom proguard.txt file, enable the User Proguard File setting in the Publishing Settings section of the Player Settings. This immediately generates the proguard.txt file in your Project’s Assets/Plugins/Android/ folder.

To learn more about ProGuard, see the ProGuard manual.

Errors when building with Gradle

If an error occurs when you use Gradle to build your app for Android, Unity displays an error dialog box. Select the Troubleshoot button to open the Gradle troubleshooting Unity documentation in your system’s browser.

Источник

Gradle for Android

Gradle is an Android build system that automates a number of build processes and prevents many common build errors. In Unity, Gradle reduces the method reference count in DEX (Dalvik Executable format) files, which means you are less likely to come across DEX limit problems.

Unity versionGradle version
2020.3 starting from 2020.3.15f1
2021.1 starting from 2021.1.16f1
6.1.1
2020.1, 2020.2, 2020.3 up to and including 2020.3.14f1
2021.1 up to and including 2021.1.15f1
5.6.4
2019.45.1.1

To learn more about:

Building or exporting a Gradle project

To build a Gradle project, follow these steps:

Exported Gradle project structure

Unity 2019.3 and newer versions create a Gradle project with two modules:

build.gradle templates

Gradle templates describe and configure how to build your Android app with Gradle. Each Gradle template represents a singleGradle project. Gradle projects can include, and depend on other Gradle projects.

A Gradle template consists of the following files:

Customizing your Gradle build

You can provide a custom Gradle build template and select minification options in the Publishing Settings section of the Player Settings Settings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary window.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unity

Providing a custom Gradle build template

You can use a custom build.gradle file for the unityLibrary module when you build the APK from Unity. This file contains specific build instructions specified in template variables. For a list of template variables, see the next section.

To use your own build.gradle file for the unityLibrary module, follow these steps:

Unity then generates a default mainTemplate.gradle file in your Project’s Assets/Plugins/Android/ folder. The path to the new file also appears under the Custom Main Gradle Template option in the Player Settings. Double-click the mainTemplate.gradle file in the Project view to open it in an external text editor.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unitymainTemplate.gradle file in the Project view for the unityLibrary module

By default, Unity uses the settingsTemplate.gradle file from the Unity install directory to create the settings.gradle file for your build. The settings.gradle file contains project components which are involved in the build process. Unity creates the following components by default, which should always be included in the settings.gradle file:

Additionally, if you add Android library plugins to your project, Unity automatically includes them in the settings file by replacing the **INCLUDES** entry.

If you want to add additional components to the settings.gradle file that Unity doesn’t include by default, create a settingsTemplate.gradle file in your project’s Assets/Plugins/Android/ folder. This overrides the default template.

If you use your own settingsTemplate.gradle file, it must contain the following lines:

IPostGenerateGradleAndroidProject

IPostGenerateGradleAndroidProject returns the path to the unityLibrary module. This keeps everything similar to versions earlier than Unity 2019.3 and doesn’t require any further changes, which means Unity can reach the app’s manifest and resources in a consistent way across versions.

Template variables

The mainTemplate.gradle file can contain the following variables:

Variable:Description:
DEPSList of project dependencies In the context of the Package Manager, a dependency is a specific package version (expressed in the form package_name@package_version ) that a project or another package requires in order to work. Projects and packages use the dependencies attribute in their manifests to define the set of packages they require. For projects, these are considered direct dependencies; for packages, these are indirect, or transitive, dependencies. More info
See in Glossary ; that is, the libraries that the Project uses.
APIVERSIONAPI version to build for (for example, 25).
MINSDKVERSIONMinimum API version (for example, 25).
BUILDTOOLSSDK Build tools used (for example, 25.0.1).
TARGETSDKVERSIONAPI version to target (for example, 25).
APPLICATIONIDAndroid Application ID (for example, com.mycompany.myapp).
MINIFY_DEBUGEnable minify for debug builds (true or false).
PROGUARD_DEBUGUse proguard for minification in debug builds (true or false.)
MINIFY_RELEASEEnable minify for release builds (true or false).
PROGUARD_RELEASEUse proguard for minification in release builds (true or false).
USER_PROGUARDCustom user proguard file (for example, proguard-user.txt ).
SIGNComplete the signingConfigs section if this build is signed.
SIGNCONFIGSet to signingConfig signingConfig.release if this build is signed.
DIR_GRADLEPROJECTThe directory where Unity creates the Gradle project.
DIR_UNITYPROJECTThe directory of your Unity Project.

Minification

You can use Proguard minification to shrink and optimize your app. To activate this option, follow these steps:

Note: Proguard might strip out important code that your app needs, so use these options carefully.

To generate a custom proguard.txt file, enable the User Proguard File setting in the Publishing Settings section of the Player Settings. This immediately generates the proguard.txt file in your Project’s Assets/Plugins/Android/ folder.

To learn more about ProGuard, see the ProGuard manual.

Errors when building with Gradle

If an error occurs when you use Gradle to build your app for Android, Unity displays an error dialog box. Select the Troubleshoot button to open the Gradle troubleshooting Unity documentation in your system’s browser.

Источник

Gradle for Android

Gradle is an Android build system that automates a number of build processes and prevents many common build errors. In Unity, Gradle reduces the method reference count in DEX (Dalvik Executable format) files, which means you are less likely to come across DEX limit problems.

Unity versionGradle version
2020.3 starting from 2020.3.15f16.1.1
2020.1, 2020.2, 2020.3 up to and including 2020.3.14f15.6.4
2019.45.1.1

To learn more about:

Building or exporting a Gradle project

To build a Gradle project, follow these steps:

Exported Gradle project structure

Unity 2019.3 and newer versions create a Gradle project with two modules:

build.gradle templates

Gradle templates describe and configure how to build your Android app with Gradle. Each Gradle template represents a singleGradle project. Gradle projects can include, and depend on other Gradle projects.

A Gradle template consists of the following files:

Customizing your Gradle build

You can provide a custom Gradle build template and select minification options in the Publishing Settings section of the Player Settings Settings that let you set various player-specific options for the final game built by Unity. More info
See in Glossary window.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unity

Providing a custom Gradle build template

You can use a custom build.gradle file for the unityLibrary module when you build the APK from Unity. This file contains specific build instructions specified in template variables. For a list of template variables, see the next section.

To use your own build.gradle file for the unityLibrary module, follow these steps:

Unity then generates a default mainTemplate.gradle file in your Project’s Assets/Plugins/Android/ folder. The path to the new file also appears under the Custom Main Gradle Template option in the Player Settings. Double-click the mainTemplate.gradle file in the Project view to open it in an external text editor.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unitymainTemplate.gradle file in the Project view for the unityLibrary module

By default, Unity uses the settingsTemplate.gradle file from the Unity install directory to create the settings.gradle file for your build. The settings.gradle file contains project components which are involved in the build process. Unity creates the following components by default, which should always be included in the settings.gradle file:

Additionally, if you add Android library plugins to your project, Unity automatically includes them in the settings file by replacing the **INCLUDES** entry.

If you want to add additional components to the settings.gradle file that Unity doesn’t include by default, create a settingsTemplate.gradle file in your project’s Assets/Plugins/Android/ folder. This overrides the default template.

If you use your own settingsTemplate.gradle file, it must contain the following lines:

IPostGenerateGradleAndroidProject

IPostGenerateGradleAndroidProject returns the path to the unityLibrary module. This keeps everything similar to versions earlier than Unity 2019.3 and doesn’t require any further changes, which means Unity can reach the app’s manifest and resources in a consistent way across versions.

Template variables

The mainTemplate.gradle file can contain the following variables:

Variable:Description:
DEPSList of project dependencies
See in Glossary ; that is, the libraries that the Project uses.
APIVERSIONAPI version to build for (for example, 25).
MINSDKVERSIONMinimum API version (for example, 25).
BUILDTOOLSSDK Build tools used (for example, 25.0.1).
TARGETSDKVERSIONAPI version to target (for example, 25).
APPLICATIONIDAndroid Application ID (for example, com.mycompany.myapp).
MINIFY_DEBUGEnable minify for debug builds (true or false).
PROGUARD_DEBUGUse proguard for minification in debug builds (true or false.)
MINIFY_RELEASEEnable minify for release builds (true or false).
PROGUARD_RELEASEUse proguard for minification in release builds (true or false).
USER_PROGUARDCustom user proguard file (for example, proguard-user.txt ).
SIGNComplete the signingConfigs section if this build is signed.
SIGNCONFIGSet to signingConfig signingConfig.release if this build is signed.
DIR_GRADLEPROJECTThe directory where Unity creates the Gradle project.
DIR_UNITYPROJECTThe directory of your Unity Project.

Minification

You can use Proguard minification to shrink and optimize your app. To activate this option, follow these steps:

Note: Proguard might strip out important code that your app needs, so use these options carefully.

To generate a custom proguard.txt file, enable the User Proguard File setting in the Publishing Settings section of the Player Settings. This immediately generates the proguard.txt file in your Project’s Assets/Plugins/Android/ folder.

To learn more about ProGuard, see the ProGuard manual.

Errors when building with Gradle

If an error occurs when you use Gradle to build your app for Android, Unity displays an error dialog box. Select the Troubleshoot button to open the Gradle troubleshooting Unity documentation in your system’s browser.

Источник

Gradle for Android

Gradle is an Android build system which automates a number of build processes. This automation means that many common build errors are less likely to occur. Most notably in Unity, it reduces the method reference count in DEX (Dalvik Executable format) files, meaning that you are less likely to come across DEX limit problems. However, due to the differences between Gradle and the default Unity Android build system, some existing projects may be hard to convert to Gradle.

You can either build the output package (APK) using the Gradle build system in Unity, or export the Gradle project and build it in an external tool (such as Android Studio).

Building with Gradle for Android

To build your Android build with Gradle in Unity:

Exporting the Gradle project

See Android Studio’s documentation on configuring your build for more information about building an output package (APK).

Providing a custom build.gradle template

which will be replaced by include directives to all your libraries.

Template Variables

These variables can be used in the mainTemplate.gradle file:

Variable:Description:
DEPSList of project dependencies; ie the libraries used.
API VERSIONAPI version to build for (eg 25).
BUILDTOOLSSDK Build tools used (eg 25.0.1).
TARGETSDKVERSIONAPI version to taget (eg 25).
APPLICATIONIDAndroid Application ID (eg com.mycompany.mygame).
MINIFY_DEBUGMinify for debug builds enabled (true or false).
PROGUARD_DEBUGUse proguard for minification (true or false.)
MINIFY_RELEASEMinify for release builds enabled (true or false).
PROGUARD_RELEASEUse proguard for minification (true or false).
USER_PROGUARDCustom user proguard file (ie progard-user.txt).
SIGNComplete signingConfigs section if build is to be signed.
SIGN_CONFIGSet to ‘signingConfig signingConfig.release’ if build is signed.
DIR_GRADLEPROJECTDirectory where the gradle project is created.
DIR_UNITYPROJECTDirectory of your Unity project.
MINSDKVERSIONMinimum API version (for example, 25).

Minification

You can activate Proguard Minification under the Minify setting on the Player window. Note that proguard can easily strip out code that is actually needed, so often this process needs to be configured carefully. You can generate a custom proguard.txt file by enabling the User Proguard File setting under the same settings as a starting point.

See the ProGuard manual for more information on Proguard.

Errors when building with Gradle

If an error occurs during building for Android using Gradle, Unity displays an error dialog box. Click Troubleshoot to open the Gradle troubleshooting Unity documentation in your system’s browser.

Что такое gradle в unity. Смотреть фото Что такое gradle в unity. Смотреть картинку Что такое gradle в unity. Картинка про Что такое gradle в unity. Фото Что такое gradle в unityUnity’s Grade build error dialog box

    2017–10–02 Page published with limited editorial review

    Expanded custom build.gradle template section.

    Did you find this page useful? Please give it a rating:

    Источник

    Добавить комментарий

    Ваш адрес email не будет опубликован. Обязательные поля помечены *