کامپوننت ها را به پروژه خود اضافه کنید
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
ردیاب مشکل مشکلات را گزارش کنید تا بتوانیم اشکالات را برطرف کنیم.
قبل از شروع، راهنمای معماری برنامه را برای اصول مفیدی که برای همه برنامههای اندروید اعمال میشود و راهنمایی در مورد استفاده از اجزای معماری با هم بخوانید.
اجزای معماری از مخزن Maven Google در دسترس هستند. برای استفاده از آنها، مخزن را به پروژه خود اضافه کنید.
فایل settings.gradle
را باز کنید و مخزن google()
را اضافه کنید:
شیار
dependencyResolutionManagement {
...
repositories {
google()
jcenter()
}
}
کاتلین
dependencyResolutionManagement {
...
repositories {
google()
jcenter()
}
}
وابستگی ها را اعلام کنید
فایل build.gradle
را برای برنامه یا ماژول خود باز کنید و مصنوعاتی را که به عنوان وابستگی نیاز دارید اضافه کنید. میتوانید برای تمام اجزای معماری وابستگی اضافه کنید یا یک زیرمجموعه انتخاب کنید.
دستورالعمل های اعلام وابستگی برای هر جزء معماری را در یادداشت های انتشار مشاهده کنید:
نسخههای AndroidX را برای بهروزترین شمارههای نسخه برای هر مؤلفه ببینید.
برای اطلاعات بیشتر درباره Refactor AndroidX و نحوه تأثیر آن بر بستههای کلاس و شناسههای ماژول، به مهاجرت به AndroidX مراجعه کنید.
کاتلین
ماژول های افزودنی Kotlin برای چندین وابستگی AndroidX پشتیبانی می شوند. این ماژول ها دارای پسوند -ktx
به نام خود هستند. به عنوان مثال:
شیار
implementation "androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version"
کاتلین
implementation("androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version")
تبدیل می شود
شیار
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"
کاتلین
implementation("androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version")
اطلاعات بیشتر، از جمله اسناد برای برنامههای افزودنی Kotlin را میتوانید در اسناد KTX بیابید.
توجه: برای برنامه های مبتنی بر Kotlin، مطمئن شوید که به جای annotationProcessor
از kapt
استفاده می کنید. همچنین باید افزونه kotlin-kapt
را اضافه کنید.
{% کلمه به کلمه %}
{% آخر کلمه %} برای شما توصیه می شود
{% کلمه به کلمه %} {% آخر کلمه %}
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی."],[],[],null,["# Add components to your project\n\n[Issue Tracker](https://issuetracker.google.com/issues/new?component=197448&template=878802)\n\nReport issues so we can fix bugs.\n\nBefore getting started, read the\n[Guide to app architecture](/topic/architecture) for useful principles that\napply to all Android apps and for guidance on\nusing architecture components together.\n\nArchitecture components are available from Google's Maven repository. To use\nthem, add the repository to your project.\n\nOpen the `settings.gradle` file and add the `google()` repository: \n\n### Groovy\n\n```groovy\ndependencyResolutionManagement {\n ...\n repositories {\n google()\n jcenter()\n }\n}\n```\n\n### Kotlin\n\n```kotlin\ndependencyResolutionManagement {\n ...\n repositories {\n google()\n jcenter()\n }\n}\n```\n| **Warning:** The JCenter repository is read-only, as of March 31, 2021. For more information, see [JCenter service update](/studio/build/jcenter-migration).\n\nDeclare dependencies\n--------------------\n\nOpen the `build.gradle` file for your app or module and add the artifacts\nthat you need as dependencies. You can add dependencies for all architecture\ncomponents or choose a subset.\n\nSee the instructions for declaring dependencies for each architecture component in the release notes:\n\n- [Futures (found in androidx.concurrent)](/jetpack/androidx/releases/concurrent)\n- [Lifecycle (including ViewModel)](/jetpack/androidx/releases/lifecycle)\n- [Navigation (including SafeArgs)](/jetpack/androidx/releases/navigation)\n- [Paging](/jetpack/androidx/releases/paging)\n- [Room](/jetpack/androidx/releases/room)\n- [WorkManager](/jetpack/androidx/releases/work)\n\nSee [AndroidX releases](/jetpack/androidx/versions) for the most up-to-date\nversion numbers for each component.\n\nFor more information about the AndroidX refactor and how it affects these class\npackages and module IDs, see [Migrate to AndroidX](/jetpack/androidx/migrate).\n\nKotlin\n------\n\nKotlin extension modules are supported for several AndroidX dependencies. These\nmodules have the suffix `-ktx` appended to their names. For example: \n\n### Groovy\n\n```groovy\nimplementation \"androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version\"\n```\n\n### Kotlin\n\n```kotlin\nimplementation(\"androidx.lifecycle:lifecycle-viewmodel:$lifecycle_version\")\n```\n\nbecomes \n\n### Groovy\n\n```groovy\nimplementation \"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version\"\n```\n\n### Kotlin\n\n```kotlin\nimplementation(\"androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version\")\n```\n\nMore information, including docs for Kotlin extensions, can be found in the\n[KTX documentation](/kotlin/ktx).\n\n**Note:** For Kotlin based apps, make sure you use\n`kapt` instead of `annotationProcessor`. You should also\nadd the `kotlin-kapt` plugin.\n\nRecommended for you\n-------------------\n\n- Note: link text is displayed when JavaScript is off\n- [App Architecture: UI Layer - Get Started - Android Developers](/topic/libraries/data-binding/start)\n- [Work with observable data objects](/topic/libraries/data-binding/observability)\n- [Migrate from Kotlin synthetics to Jetpack view binding](/topic/libraries/view-binding/migration)"]]