Gradle の場合は、Compose Compiler Gradle プラグインを使用して Compose を設定します。
Gradle バージョン カタログで設定する
Compose Compiler Gradle プラグインを設定します。
libs.versions.tomlファイルで、Compose コンパイラへの参照を削除します。versionsセクションとpluginsセクションに、新しい依存関係を追加します。[versions] kotlin = "2.3.21" [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.21" // 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.21")
}
}
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.06.00)を使用します。
Android の BuildFeatures ブロックの内側で compose フラグを true に設定すると、Android Studio で 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.06.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.06.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")
}
compileSdk と Android Gradle プラグインの互換性
Compose ライブラリのリリースでは、最新の compileSdk バージョンが継続的に採用され、最新の Android 機能を利用できるようになっています。新しい compileSdk バージョンでは、新しいバージョンの Android Gradle プラグインが必要になります。そのため、新しい Compose リリースを採用するには、プロジェクトで新しいバージョンの Android Gradle プラグインを採用する必要があります。プロジェクトの compileSdk は、最新のリリース バージョンで最新の状態に保つことをおすすめします。compileSdk は targetSdk とは無関係です。
たとえば、Compose 1.12.0 以降では、プロジェクトで compileSdk 37 と Android Gradle プラグイン(AGP)9 を使用する必要があります。
さまざまな API レベルでサポートされている AGP のバージョンを確認するには、Android Gradle プラグインの API レベルのサポートに関するドキュメントをご覧ください。