Compose कंपाइलर Gradle प्लगिन सेट अप करना

Gradle का इस्तेमाल करने वाले लोग, Compose Compiler Gradle प्लगिन का इस्तेमाल करके, Compose को आसानी से सेट अप और कॉन्फ़िगर कर सकते हैं.

Gradle वर्शन कैटलॉग की मदद से सेट अप करना

यहां दिए गए निर्देशों में, Compose Compiler Gradle प्लगिन को सेट अप करने का तरीका बताया गया है:

  1. अपनी libs.versions.toml फ़ाइल में, Compose Compiler के सभी रेफ़रंस हटाएं.
  2. प्लगिन सेक्शन में, यह नई डिपेंडेंसी जोड़ें.
[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. अपने प्रोजेक्ट की रूट build.gradle.kts फ़ाइल में, plugins सेक्शन में यह स्निपेट जोड़ें.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler) apply false
}
  1. Compose का इस्तेमाल करने वाले हर मॉड्यूल में, प्लगिन को इस तरह लागू करें.
plugins {
   // Existing plugins
   alias(libs.plugins.compose.compiler)
}

अगर डिफ़ॉल्ट सेट अप का इस्तेमाल किया जा रहा है, तो अब आपका ऐप्लिकेशन बन जाना चाहिए और कंपाइल हो जाना चाहिए. अगर आपने Compose कंपाइलर पर कस्टम विकल्प कॉन्फ़िगर किए थे, तो यहां दिया गया सेक्शन देखें.

Gradle वर्शन कैटलॉग के बिना कंपोज़ कंपाइलर सेट अप करना

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 Compiler Gradle Plugin के साथ कॉन्फ़िगरेशन के विकल्प

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

}