إعداد المكوّن الإضافي 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.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" }
  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، اتّبِع القسم التالي.

إعداد أداة تجميع Compose بدون كتالوجات إصدارات Gradle

أضِف المكوّن الإضافي إلى ملفات build.gradle.kts المرتبطة بالوحدات التي يتم فيها استخدام Compose:

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

لضبط أداة تجميع Compose باستخدام المكوّن الإضافي Gradle، أضِف كتلة composeCompiler إلى ملف build.gradle.kts الخاص بالوحدة على المستوى الأعلى:

android {  }

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

للاطّلاع على القائمة الكاملة بالخيارات المتاحة، يُرجى الرجوع إلى المستندات.

إعداد تبعيات Compose

استخدِم دائمًا أحدث إصدار من قائمة مواد Compose: 2026.04.01.

اضبط العلامة compose على true داخل BuildFeatures في Android لتفعيل وظائف Compose في "استوديو Android".

أضِف التعريف التالي إلى ملف build.gradle في تطبيقك:

أنيق

android {
    buildFeatures {
        compose true
    }
}

Kotlin

android {
    buildFeatures {
        compose = true
    }
}

أضِف قائمة مواد Compose والمجموعة الفرعية من تبعيات مكتبة Compose:

أنيق

dependencies {

    def composeBom = platform('androidx.compose:compose-bom:2026.04.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.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.04.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.10.0")
    // Optional - Integration with LiveData
    implementation("androidx.compose.runtime:runtime-livedata")
    // Optional - Integration with RxJava
    implementation("androidx.compose.runtime:runtime-rxjava2")

}