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는 모든 Android 빌드에 Gradle을 사용합니다. Unity에서 출력 패키지(.apk, .aab)를 빌드하거나, Unity에서 Gradle 프로젝트를 익스포트한 후 Android Studio와 같은 외부 툴로 빌드할 수 있습니다.
Unity 버전 | Gradle version |
---|---|
2020.1 | 5.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, and 2019.1 up to and including 2019.1.6f1 | 4.6 |
2018.2 | 4.2.1 |
2018.1 | 4.0.1 |
2017.4, starting from 2017.4.17 | 4.6 |
2017.4 up to and including 2017.4.16 | 4.0.1 |
2017.1, 2017.2 | 2.14 |
자세한 내용은 다음을 참조하십시오.
Gradle 프로젝트를 빌드하려면 다음 절차를 따르십시오.
다음 버튼을 선택하십시오.
Unity 프로젝트를 Gradle 프로젝트로 익스포트하려면 Export Project 설정을 활성화한 후 Export 버튼을 선택하십시오. 이렇게 하면 Unity가 지정한 폴더에 Gradle 프로젝트를 생성하고 .apk 파일을 빌드하지 않습니다. 이 프로젝트를 Android Studio 또는 다른 외부 툴로 임포트하여 추가 변경을 수행하거나 해당 툴에서 빌드할 수 있습니다.
Unity 2019.3 이상 버전은 다음의 두 가지 모듈이 포함된 Gradle 프로젝트를 만듭니다.
Gradle 템플릿은 Gradle을 사용하여 Android 앱을 빌드하는 방법을 설명하고 구성합니다. 각 Gradle 템플릿은 하나의 singleGradle 프로젝트를 나타냅니다. Gradle 프로젝트는 다른 Gradle 프로젝트를 포함하거나 사용할 수 있습니다.
Gradle 템플릿은 다음의 파일로 구성됩니다.
파일 | 위치 | 포함 |
---|---|---|
baseProjectTemplate.gradle |
In the exported project, root/build.gradle folder |
다른 모든 템플릿/Gradle 프로젝트(저장소 및 Android Gradle 플러그인에 대한 종속성) 간에 공유되는 설정이 들어 있습니다. |
launcherTemplate.gradle_ |
In the exported project, root/launcher/build.gradle folder
|
Android 애플리케이션을 빌드하는 방법(번들 생성, 서명, APK 분할)에 대한 지침이 들어 있습니다. unityLibrary 프로젝트에 기반하고 .apk 파일 또는 앱 번들을 출력합니다. |
mainTemplate.gradle |
In the exported project, root/unityLibrary/build.gradle folder |
Contains instructions on how to build Unity as a Library. Outputs an .aar file. You can override the Unity template with a custom template in the Unity Editor. See the Providing a custom Gradle build template section on this page for more details. |
libTemplate.gradle |
다양함 | Unity 프로젝트에 Android 라이브러리 프로젝트가 플러그인으로 포함된 경우에 사용됩니다. |
커스텀 Gradle 빌드 템플릿을 제공하고 플레이어 설정 창의 Publishing Settings 섹션에서 축소 옵션을 선택할 수 있습니다.
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.
mainTemplate.gradle
file in the Project view for the unityLibrary moduleYou 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:
**INCLUDES**
Unity는 이 줄을 모든 프로젝트 라이브러리에 대한 include 지시문으로 교체합니다.
IPostGenerateGradleAndroidProject은 unityLibrary 모듈에 대한 경로를 반환합니다. 이렇게 하면 모든 요소가 Unity 2019.3 이전 버전과 유사하게 유지되므로 추가 변경이 필요하지 않습니다. 즉 Unity는 여러 버전에서 일관된 방식으로 앱의 매니페스트와 리소스에 도달할 수 있습니다.
The mainTemplate.gradle
file can contain the following variables:
변수: | 설명: |
---|---|
DEPS | 프로젝트 종속성 리스트, 즉 프로젝트가 사용하는 라이브러리입니다. |
APIVERSION | 빌드할 API 버전입니다(예: 25). |
MINSDKVERSION | 최소 API 버전입니다(예: 25). |
BUILDTOOLS | 사용되는 SDK 빌드 툴입니다(예: 25.0.1). |
TARGETSDKVERSION | 대상으로 할 API 버전입니다(예: 25). |
APPLICATIONID | Android 애플리케이션 ID(예: com.mycompany.myapp)입니다. |
MINIFY_DEBUG | 디버그 빌드의 축소를 활성화합니다(true 또는 false). |
PROGUARD_DEBUG | 디버그 빌드의 축소에 ProGuard를 사용합니다(true 또는 false). |
MINIFY_RELEASE | 릴리스 빌드의 축소를 활성화합니다(true 또는 false). |
PROGUARD_RELEASE | 릴리스 빌드의 축소에 ProGuard를 사용합니다(true 또는 false). |
USER_PROGUARD | Custom user proguard file (for example, proguard-user.txt ). |
SIGN | 이 빌드가 서명되어 있으면 signingConfigs 섹션을 완성합니다. |
SIGNCONFIG | 이 빌드가 서명되어 있으면 signingConfig signingConfig.release 로 설정됩니다. |
DIR_GRADLEPROJECT | Unity가 Gradle 프로젝트를 만드는 디렉토리입니다. |
DIR_UNITYPROJECT | Unity 프로젝트의 디렉토리입니다. |
ProGuard 축소를 사용하여 앱 크기를 줄이고 앱을 최적화합니다. 이 옵션을 활성화하려면 다음 절차를 따르십시오.
참고: ProGuard가 앱에 필요한 중요한 코드를 삭제할 수도 있으므로 이 옵션은 신중하게 사용해야 합니다.
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.
ProGuard에 대한 자세한 내용은 ProGuard 매뉴얼을 참조하십시오.
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.