Compose Compiler Gradle प्लग इन सेट अप करना
Gradle के लिए, Compose को सेट अप और कॉन्फ़िगर करने के लिए, Compose Compiler Gradle प्लग इन का इस्तेमाल करें.
Gradle के वर्शन कैटलॉग की मदद से सेट अप करना
Compose Compiler Gradle प्लग इन सेट अप करने के लिए:
libs.versions.tomlफ़ाइल में, Compose Compiler के किसी भी रेफ़रंस को हटाएं.versionsऔरpluginsसेक्शन में, नई डिपेंडेंसी जोड़ें:
[versions]
kotlin = "2.3.21"
[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" }
- प्रोजेक्ट की रूट
build.gradle.ktsफ़ाइल में,pluginsसेक्शन में यह जानकारी जोड़ें.
plugins {
// Existing plugins
alias(libs.plugins.compose.compiler) apply false
}
- Compose का इस्तेमाल करने वाले हर मॉड्यूल में, प्लग इन लागू करें:
plugins {
// Existing plugins
alias(libs.plugins.compose.compiler)
}
अगर प्रोजेक्ट को डिफ़ॉल्ट सेट अप का इस्तेमाल करके बनाया गया था, तो अब उसे बनाया और कंपाइल किया जाना चाहिए. अगर Compose कंपाइलर पर कस्टम विकल्प कॉन्फ़िगर किए गए थे, तो अगला सेक्शन पढ़ें.
Gradle के वर्शन कैटलॉग के बिना, Compose Compiler सेट अप करना
Compose का इस्तेमाल करने वाले मॉड्यूल से जुड़ी build.gradle.kts फ़ाइलों में प्लग इन जोड़ें:
plugins {
id("org.jetbrains.kotlin.plugin.compose") version "2.3.21" // 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.21")
}
}
Compose Compiler 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 बीओएम के सबसे नए वर्शन 2026.05.00 का इस्तेमाल करें.
Android Studio में Compose की सुविधा चालू करने के लिए, Android BuildFeatures
में compose फ़्लैग को true पर सेट करें.
अपने ऐप्लिकेशन की build.gradle फ़ाइल में, यह परिभाषा जोड़ें:
शानदार
android {
buildFeatures {
compose true
}
}
Kotlin
android {
buildFeatures {
compose = true
}
}
Compose बीओएम और Compose लाइब्रेरी डिपेंडेंसी का सबसेट जोड़ें:
शानदार
dependencies {
def composeBom = platform('androidx.compose:compose-bom:2026.05.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.05.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")
}