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

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

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

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

  1. libs.versions.toml फ़ाइल में, Compose कंपाइलर का कोई भी रेफ़रंस हटाएं.
  2. versions और plugins सेक्शन में, नई डिपेंडेंसी जोड़ें:

    [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" }
    
  3. प्रोजेक्ट की रूट build.gradle.kts फ़ाइल में, plugins सेक्शन में यह जोड़ें.

    plugins {
    // Existing plugins
    alias(libs.plugins.compose.compiler) apply false
    }
    
  4. Compose का इस्तेमाल करने वाले हर मॉड्यूल में, प्लगिन लागू करें:

    plugins {
    // Existing plugins
    alias(libs.plugins.compose.compiler)
    }
    

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

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

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

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

Compose Compiler Gradle प्लग इन के साथ कॉन्फ़िगरेशन के विकल्प

Gradle प्लग इन का इस्तेमाल करके Compose कंपाइलर को कॉन्फ़िगर करने के लिए, मॉड्यूल की build.gradle.kts फ़ाइल में सबसे ऊपर composeCompiler ब्लॉक जोड़ें:

android { … }

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

उपलब्ध विकल्पों की पूरी सूची देखने के लिए, दस्तावेज़ देखें.

Compose की डिपेंडेंसी सेट अप करना

हमेशा Compose बीओएम के सबसे नए वर्शन का इस्तेमाल करें: 2026.11.01.

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

अपने ऐप्लिकेशन की build.gradle फ़ाइल में यह परिभाषा जोड़ें:

Groovy

android {
    buildFeatures {
        compose true
    }
}

Kotlin

android {
    buildFeatures {
        compose = true
    }
}

Compose बीओएम और Compose लाइब्रेरी डिपेंडेंसी का सबसेट जोड़ें:

Groovy

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 और Android Gradle प्लगिन के साथ काम करने की सुविधा

Compose लाइब्रेरी के रिलीज़, लगातार नए compileSdk वर्शन को अपनाते हैं, ताकि Android की नई सुविधाओं का ऐक्सेस दिया जा सके. compileSdk के नए वर्शन के लिए, Android Gradle प्लगिन के नए वर्शन की ज़रूरत होती है. इसलिए, Compose की नई रिलीज़ को अपनाने के लिए, प्रोजेक्ट को Android Gradle प्लगिन के नए वर्शन भी अपनाने होंगे. हमारा सुझाव है कि आप अपने प्रोजेक्ट के compileSdk को रिलीज़ किए गए नए वर्शन के साथ अप-टू-डेट रखें. compileSdk, targetSdk से अलग है.

उदाहरण के लिए, Compose 1.12.0 और इसके बाद के वर्शन में, प्रोजेक्ट के लिए compileSdk 37 और Android Gradle प्लगिन (AGP) 9 का इस्तेमाल करना ज़रूरी है.

यह देखने के लिए कि एजीपी का कौनसा वर्शन, अलग-अलग एपीआई लेवल के साथ काम करता है, Android Gradle प्लगिन के एपीआई लेवल के साथ काम करने की सुविधा से जुड़ा दस्तावेज़ देखें.