Compose Compiler Gradle eklentisini ayarlama

Gradle kullanıcıları, Compose'u ayarlamayı ve yapılandırmayı kolaylaştırmak için Compose Compiler Gradle eklentisini kullanabilir.

Gradle sürüm kataloglarıyla kurulum

Aşağıdaki talimatlarda, Compose Compiler Gradle eklentisini nasıl ayarlayabileceğiniz açıklanmaktadır:

  1. libs.versions.toml dosyanızda Compose Compiler'a yapılan tüm referansları kaldırın.
  2. Eklentiler bölümünde aşağıdaki yeni bağımlılığı ekleyin.
[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" }
  1. Projelerinizin kök build.gradle.kts dosyasına aşağıdaki snippet'i eklentiler bölümüne ekleyin.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler) apply false
}
  1. Compose'u kullanan her modülde eklentiyi aşağıdaki şekilde uygulayın.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler)
}

Varsayılan kurulumu kullanıyorsanız uygulamanız artık derlenip oluşturulmalıdır. Compose derleyicisinde özel seçenekler yapılandırdıysanız aşağıdaki bölümü inceleyin.

Gradle sürüm katalogları olmadan Compose Compiler'ı ayarlama

Kullandığınız Compose modülleriyle ilişkili build.gradle.kts dosyalarına aşağıdaki eklentiyi ekleyin:

plugins {
    id("org.jetbrains.kotlin.plugin.compose") version "2.0.0" // this version matches your Kotlin version
}

Bu sınıf yolunu üst düzey proje build.gradle.kts dosyanıza da eklemeniz gerekebilir:

buildscript {
    dependencies {
        classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:2.0.0")
    }
}

Compose Compiler Gradle eklentisiyle yapılandırma seçenekleri

Gradle eklentisini kullanarak Compose derleyicisini 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")
    stabilityConfigurationFile = 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

Uygulamanızın build.gradle dosyasına aşağıdaki tanımı ekleyin:

Groovy

android {
    buildFeatures {
        compose true
    }
}

Kotlin

android {
    buildFeatures {
        compose = true
    }
}

Android BuildFeatures bloğunda compose işaretini true olarak ayarlamak, Android Studio'da Compose işlevini etkinleştirir.

Son olarak, aşağıdaki bloktan bağımlılıklarınıza Compose BOM'u ve ihtiyacınız olan Compose kitaplığı bağımlılıklarının alt kümesini ekleyin:

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")

}