Compose Compiler Gradle プラグインを設定する
Gradle ユーザーは、Compose Compiler Gradle プラグインを使用して、Compose の設定と構成を簡単に行うことができます。
Gradle バージョン カタログで設定する
Compose Compiler Gradle プラグインを設定する手順は次のとおりです。
libs.versions.tomlファイルで、Compose コンパイラへの参照を削除します。- plugins セクションに、次の新しい依存関係を追加します。
[versions]
kotlin = "2.0.0"
[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.0.0" // 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.0.0")
}
}
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 の依存関係を設定する
アプリの build.gradle ファイルに次の定義を追加します。
Groovy
android {
buildFeatures {
compose true
}
}
Kotlin
android {
buildFeatures {
compose = true
}
}
Android の BuildFeatures ブロックの内側で compose フラグを true に設定すると、Android Studio で Compose 機能が有効になります。
最後に、次のブロックから、Compose BOM と Compose ライブラリ依存関係の必要なサブセットを依存関係に追加します。
Groovy
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2026.01.01')
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.11.0'
// Optional - Integration with ViewModels
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5'
// 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.01.01")
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.11.0")
// Optional - Integration with ViewModels
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.5")
// Optional - Integration with LiveData
implementation("androidx.compose.runtime:runtime-livedata")
// Optional - Integration with RxJava
implementation("androidx.compose.runtime:runtime-rxjava2")
}