Gradle için Compose'u ayarlamak ve yapılandırmak üzere Compose Compiler Gradle eklentisini kullanın.
Gradle sürüm kataloglarıyla kurulum
Compose Derleyici Gradle eklentisini ayarlayın:
libs.versions.tomldosyasında, Compose derleyicisine yapılan tüm referansları kaldırın.versionsvepluginsbölümlerine yeni bağımlılığı ekleyin:[versions] kotlin = "2.4.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" }Projenin kök
build.gradle.ktsdosyasında,pluginsbölümüne aşağıdakileri ekleyin.plugins { // Existing plugins alias(libs.plugins.compose.compiler) apply false }Compose'u kullanan her modülde eklentiyi uygulayın:
plugins { // Existing plugins alias(libs.plugins.compose.compiler) }
Varsayılan kurulum kullanılıyorsa proje artık derlenebilir. Oluşturma derleyicisinde özel seçenekler yapılandırdıysa sonraki bölümü uygulayın.
Compose derleyicisini Gradle sürüm katalogları olmadan ayarlama
Eklentiyi, Compose'un kullanıldığı modüllerle ilişkili build.gradle.kts dosyalarına ekleyin:
plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.4.10" // this version matches your Kotlin version
}
Sınıf yolunu üst düzey proje build.gradle.kts dosyanıza ekleyin:
buildscript {
dependencies {
classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:2.4.10")
}
}
Compose Compiler Gradle eklentisiyle yapılandırma seçenekleri
Compose derleyicisini Gradle eklentisini kullanarak yapılandırmak için modülün build.gradle.kts dosyasına en üst düzeyde composeCompiler bloğunu ekleyin:
android { … }
composeCompiler {
reportsDestination = layout.buildDirectory.dir("compose_compiler")
stabilityConfigurationFiles.add(rootProject.layout.projectDirectory.file("stability_config.conf"))
}
Kullanılabilir seçeneklerin tam listesi için belgelere bakın.
Compose bağımlılıklarını ayarlama
Her zaman en yeni Compose BOM sürümünü kullanın: 2026.11.01.
Android Studio'da Compose işlevini etkinleştirmek için Android BuildFeatures içinde compose işaretini true olarak ayarlayın.
Uygulamanızın build.gradle dosyasına aşağıdaki tanımı ekleyin:
Modern
android {
buildFeatures {
compose true
}
}
Kotlin
android {
buildFeatures {
compose = true
}
}
Compose BOM'u ve Compose kitaplığı bağımlılıklarının alt kümesini ekleyin:
Modern
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2026.11.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.13.0'
// Optional - Integration with ViewModels
implementation 'androidx.lifecycle:lifecycle-viewmodel-compose:2.11.1'
// 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.11.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.13.0")
// Optional - Integration with ViewModels
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.11.1")
// Optional - Integration with LiveData
implementation("androidx.compose.runtime:runtime-livedata")
// Optional - Integration with RxJava
implementation("androidx.compose.runtime:runtime-rxjava2")
}
compileSdk ve Android Gradle eklentisi uyumluluğu
Compose kitaplığı sürümleri, en yeni Android özelliklerine erişim sağlamak için sürekli olarak en yeni compileSdk sürümlerini kullanır. Daha yeni compileSdk sürümleri, Android Gradle eklentisinin daha yeni sürümlerini gerektirir. Bu nedenle, yeni Oluşturma sürümlerini kullanmak için projelerin Android Gradle eklentisinin yeni sürümlerini de kullanması gerekir. Projenizin compileSdk dosyasını en son yayınlanan sürümlerle güncel tutmanızı öneririz. compileSdk, targetSdk ile ilişkili değil.
Örneğin, Compose 1.12.0'dan itibaren projelerin compileSdk 37 ve Android Gradle eklentisi (AGP) 9'u kullanması gerekir.
Farklı API düzeyleri için hangi AGP sürümünün desteklendiğini kontrol etmek istiyorsanız Android Gradle eklentisi API düzeyi desteği dokümanlarına göz atın.