Compose 컴파일러 Gradle 플러그인 설정
Gradle의 경우 Compose 컴파일러 Gradle 플러그인을 사용하여 Compose를 설정하고 구성합니다.
Gradle 버전 카탈로그로 설정
Compose 컴파일러 Gradle 플러그인을 설정합니다.
libs.versions.toml파일에서 Compose 컴파일러에 대한 참조를 삭제합니다.versions및plugins섹션에 새 종속 항목을 추가합니다.
[versions]
kotlin = "2.3.10"
[plugins]
org-jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
// Add this line
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
- 프로젝트의 루트
build.gradle.kts파일에서plugins섹션에 다음을 추가합니다.
plugins {
// Existing plugins
alias(libs.plugins.compose.compiler) apply false
}
- Compose를 사용하는 각 모듈에서 플러그인을 적용합니다.
plugins {
// Existing plugins
alias(libs.plugins.compose.compiler)
}
기본 설정을 사용한 경우 이제 프로젝트가 빌드되고 컴파일됩니다. Compose 컴파일러에서 맞춤 옵션을 구성한 경우 다음 섹션을 따르세요.
Gradle 버전 카탈로그 없이 Compose 컴파일러 설정
Compose가 사용되는 모듈과 연결된 build.gradle.kts 파일에 플러그인을 추가합니다.
plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.3.10" // this version matches your Kotlin version
}
최상위 프로젝트 build.gradle.kts 파일에 클래스 경로를 추가합니다.
buildscript {
dependencies {
classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:2.3.10")
}
}
Compose 컴파일러 Gradle 플러그인의 구성 옵션
Gradle 플러그인을 사용하여 Compose 컴파일러를 구성하려면 최상위 수준에서 모듈의 build.gradle.kts 파일에 composeCompiler 블록을 추가하세요.
android { … }
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}
사용 가능한 옵션의 전체 목록은 문서를 참고하세요.
Compose 종속 항목 설정
항상 최신 Compose BOM 버전(2026.03.00)을 사용하세요.
Android BuildFeatures 내에서 compose 플래그를 true로 설정하여 Android 스튜디오에서 Compose 기능을 사용 설정합니다.
앱의 build.gradle 파일에 다음 정의를 추가하세요.
Groovy
android {
buildFeatures {
compose true
}
}
Kotlin
android {
buildFeatures {
compose = true
}
}
Compose BOM과 Compose 라이브러리 종속 항목의 하위 집합을 추가합니다.
Groovy
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2026.03.00')
implementation composeBom
androidTestImplementation composeBom
// Choose one of the following:
// Material Design 3
implementation 'androidx.compose.material3:material3'
// or skip Material Design and build directly on top of foundational components
implementation 'androidx.compose.foundation:foundation'
// or only import the main APIs for the underlying toolkit systems,
// such as input and measurement/layout
implementation 'androidx.compose.ui:ui'
// Android Studio Preview support
implementation 'androidx.compose.ui:ui-tooling-preview'
debugImplementation 'androidx.compose.ui:ui-tooling'
// UI Tests
androidTestImplementation 'androidx.compose.ui:ui-test-junit4'
debugImplementation 'androidx.compose.ui:ui-test-manifest'
// Optional - Add window size utils
implementation 'androidx.compose.material3.adaptive:adaptive'
// Optional - Integration with activities
implementation 'androidx.activity:activity-compose:1.13.0'
// Optional - Integration with ViewModels
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0'
// Optional - Integration with LiveData
implementation 'androidx.compose.runtime:runtime-livedata'
// Optional - Integration with RxJava
implementation 'androidx.compose.runtime:runtime-rxjava2'
}
Kotlin
dependencies {
val composeBom = platform("androidx.compose:compose-bom:2026.03.00")
implementation(composeBom)
androidTestImplementation(composeBom)
// Choose one of the following:
// Material Design 3
implementation("androidx.compose.material3:material3")
// or skip Material Design and build directly on top of foundational components
implementation("androidx.compose.foundation:foundation")
// or only import the main APIs for the underlying toolkit systems,
// such as input and measurement/layout
implementation("androidx.compose.ui:ui")
// Android Studio Preview support
implementation("androidx.compose.ui:ui-tooling-preview")
debugImplementation("androidx.compose.ui:ui-tooling")
// UI Tests
androidTestImplementation("androidx.compose.ui:ui-test-junit4")
debugImplementation("androidx.compose.ui:ui-test-manifest")
// Optional - Add window size utils
implementation("androidx.compose.material3.adaptive:adaptive")
// Optional - Integration with activities
implementation("androidx.activity:activity-compose:1.13.0")
// Optional - Integration with ViewModels
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.10.0")
// Optional - Integration with LiveData
implementation("androidx.compose.runtime:runtime-livedata")
// Optional - Integration with RxJava
implementation("androidx.compose.runtime:runtime-rxjava2")
}