Menyiapkan plugin Gradle Compose Compiler

Untuk Gradle, gunakan plugin Gradle Compose Compiler untuk menyiapkan dan mengonfigurasi Compose.

Menyiapkan dengan katalog versi Gradle

Siapkan plugin Gradle Compose Compiler:

  1. Di file libs.versions.toml, hapus referensi ke Compose Compiler.
  2. Di bagian versions dan plugins, tambahkan dependensi baru:
[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" }
  1. Di file build.gradle.kts root project, tambahkan hal berikut ke bagian plugins.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler) apply false
}
  1. Di setiap modul yang menggunakan Compose, terapkan plugin:
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler)
}

Project kini harus di-build dan dikompilasi jika menggunakan penyiapan default. Jika project telah mengonfigurasi opsi kustom di compiler Compose, ikuti bagian berikutnya.

Menyiapkan Compose Compiler tanpa katalog versi Gradle

Tambahkan plugin ke file build.gradle.kts yang terkait dengan modul tempat Compose digunakan:

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

Tambahkan classpath ke file build.gradle.kts project level teratas:

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

Opsi konfigurasi dengan Plugin Gradle Compose Compiler

Untuk mengonfigurasi compiler Compose menggunakan plugin Gradle, tambahkan blok composeCompiler ke file build.gradle.kts modul di level teratas:

android {  }

composeCompiler {
    reportsDestination = layout.buildDirectory.dir("compose_compiler")
    stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}

Untuk mengetahui daftar lengkap opsi yang tersedia, lihat dokumentasi.

Menyiapkan dependensi Compose

Selalu gunakan versi BOM Compose terbaru: 2026.03.00.

Tetapkan tanda compose ke true di dalam BuildFeatures Android untuk mengaktifkan fungsi Compose di Android Studio.

Tambahkan definisi berikut ke file build.gradle aplikasi Anda:

Groovy

android {
    buildFeatures {
        compose true
    }
}

Kotlin

android {
    buildFeatures {
        compose = true
    }
}

Tambahkan BOM Compose dan subset dependensi library 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")

}