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

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

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

Compose Compiler Gradle प्लगिन सेट अप करें:

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

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

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

Compose का इस्तेमाल करने वाले मॉड्यूल से जुड़ी build.gradle.kts फ़ाइलों में प्लगिन जोड़ें:

plugins {
    id("org.jetbrains.kotlin.plugin.compose") version "2.3.10" // 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.10")
    }
}

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.03.00 का इस्तेमाल करें.

Android Studio में Compose की सुविधा चालू करने के लिए, Android BuildFeatures में compose फ़्लैग को true पर सेट करें.

अपने ऐप्लिकेशन की 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.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")

}