Version: 2022.3
언어: 한국어
Android용 빌드 및 배포
Android 앱 매니페스트 오버라이드

Gradle 템플릿

Gradle 템플릿은 Gradle을 사용하여 Android 애플리케이션을 빌드하는 방법을 설정합니다. 각 Gradle 템플릿은 단일 Gradle 프로젝트를 나타냅니다. Gradle 프로젝트는 다른 Gradle 프로젝트를 포함하고 이에 의존할 수 있습니다.

Gradle 템플릿 파일

Gradle 템플릿은 다음의 파일로 구성됩니다.

File 위치 내용물
baseProjectTemplate.gradle 익스포트한 프로젝트의 root/build.gradle 폴더 최종 Gradle 프로젝트의 모든 모듈에 영향을 미치는 설정 정보가 있습니다. 사용할 Android Gradle 플러그인 버전과 Java 플러그인의 위치를 지정합니다. 이 위치는 프로젝트 내부의 온라인 저장소와 Java 플러그인을 조합하여 지정합니다.
launcherTemplate.gradle 익스포트한 프로젝트의 root/launcher/build.gradle 폴더 Android 애플리케이션을 빌드하는 방법에 대한 명령어가 있습니다. 여기에는 번들링, 서명, APK를 나누는지 여부가 포함됩니다. unityLibrary 프로젝트에 따라 다르며 .apk 파일이나 앱 번들을 출력합니다.
mainTemplate.gradle 익스포트한 프로젝트의 root/unityLibrary/build.gradle 폴더 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.
libTemplate.gradle 다양함 Android 라이브러리 프로젝트 플러그인에 build.gradle 파일이 포함되어 있지 않은 경우 Unity는 파일을 생성하기 위해 libTemplate.gradle 파일을 템플릿으로 사용합니다. Unity가 build.gradle 파일을 생성한 후 또는 플러그인 디렉토리에 이미 파일이 존재하는 경우 Unity는 플러그인을 Gradle 프로젝트에 복사합니다.
settingsTemplate.gradle In the exported project, root/settings.gradle file 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.
gradleTemplate.properties In the exported project, root/gradle.properties file Configures the Gradle build system and specifies properties such as the size of the Java virtual machine (JVM) heap

커스텀 Gradle 템플릿 사용

To have more control over the Gradle project files that Unity produces, you can override Unity’s default Gradle template files. To do this:

  1. Edit > Project Settings로 이동하여 프로젝트 설정 창을 엽니다.
  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 format and contents of the final Gradle project file.

템플릿 변수

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

변수 설명
DEPS 프로젝트 종속성 리스트입니다. 이는 해당 프로젝트가 사용하는 라이브러리의 리스트입니다.
APIVERSION 빌드할 API 버전입니다. Unity는 해당 버전과 TARGETSDKVERSION을 같은 값(Android 플레이어 설정Target API Level)으로 설정합니다.
MINSDKVERSION 애플리케이션을 지원하는 최소 API 버전입니다.
BUILDTOOLS 사용할 SDK 빌드 툴입니다.
TARGETSDKVERSION 대상으로 지정할 API 버전입니다. Unity는 해당 버전과 APIVERSION을 같은 값(Android 플레이어 설정Target API Level)으로 설정합니다.
APPLICATIONID Android 애플리케이션 ID입니다. 예: com.mycompany.myapp
MINIFY_DEBUG 디버그 빌드를 축소할지 여부를 나타냅니다.
PROGUARD_DEBUG 디버그 빌드에서 축소화를 위해 ProGuard를 사용할지 여부를 나타냅니다.
MINIFY_RELEASE 릴리스 빌드를 축소할지 여부를 나타냅니다.
PROGUARD_RELEASE 릴리스 빌드에서 축소화를 위해 ProGuard를 사용할지 여부를 나타냅니다.
USER_PROGUARD 축소화를 위해 사용할 커스텀 ProGuard 파일을 지정합니다.
SIGN 이 빌드가 서명된 경우 signingConfigs 섹션을 완료합니다.
SIGNCONFIG 빌드가 서명될지 여부를 나타냅니다. 이 프로퍼티가 signingConfig.release로 설정되면 빌드가 서명됩니다.
DIR_GRADLEPROJECT Unity가 Gradle 프로젝트를 만드는 디렉토리입니다.
DIR_UNITYPROJECT Unity 프로젝트의 디렉토리입니다.
PLAY_ASSET_PACKS Specifies the asset packs to include in your application.

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.

C#을 사용하여 익스포트한 Gradle 프로젝트 수정

Unity에서 조합된 Gradle 프로젝트를 수정하려면 IPostGenerateGradleAndroidProject에서 상속된 클래스를 생성하고 OnPostGenerateGradleAndroidProject 함수를 오버라이드합니다. 이 함수는 unityLibrary 모듈에 대한 경로를 파라미터로 수신하며 이를 사용하여 C# 스크립팅을 통해 애플리케이션 매니페스트와 리소스에 도달할 수 있습니다.

경고: 이제 Unity는 증분 빌드 파이프라인을 사용하며 이는 Unity가 연속된 빌드에 대해 동일한 Gradle 프로젝트를 다시 사용한다는 의미입니다. 즉 Unity가 모든 빌드에 대해 더 이상 새로운 Gradle 프로젝트를 생성하지 않기 때문에 API를 사용하여 수행하는 모든 수정 사항이 누적됩니다. 예를 들어 이 API를 사용하여 추가 파일을 Gradle 프로젝트에 추가한다면 예상대로 첫 번째 빌드는 작동하지만 두 번째 빌드를 하는 동안에는 해당 파일이 이미 존재합니다. 다른 예로는 이 API를 사용하여 특정 파일에 권한을 추가하는 경우입니다. 각 연속 빌드는 권한에 대해 다른 엔트리를 추가합니다. 수정할 사항이 빌드에 이미 존재하지 않는지 확인하는 것이 중요합니다.

Android용 빌드 및 배포
Android 앱 매니페스트 오버라이드
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961