توجه: با انتشار اندروید 9.0 (سطح API 28) نسخه جدیدی از کتابخانه پشتیبانی به نام AndroidX وجود دارد که بخشی از Jetpack است. کتابخانه AndroidX شامل کتابخانه پشتیبانی موجود و همچنین شامل آخرین اجزای Jetpack است.
می توانید به استفاده از کتابخانه پشتیبانی ادامه دهید. مصنوعات تاریخی (آنهایی که نسخه 27 و قبل از آن منتشر شده اند و به عنوان android.support.*
) در Google Maven در دسترس خواهند بود. با این حال، تمام توسعه کتابخانه جدید در کتابخانه AndroidX رخ خواهد داد.
توصیه می کنیم از کتابخانه های AndroidX در تمام پروژه های جدید استفاده کنید. همچنین باید پروژه های موجود را به AndroidX منتقل کنید .
نحوه راهاندازی کتابخانههای پشتیبانی Android در پروژه توسعه به این بستگی دارد که میخواهید از چه ویژگیهایی استفاده کنید و چه طیفی از نسخههای پلتفرم Android را میخواهید با برنامه خود پشتیبانی کنید.
این سند شما را از طریق دانلود بسته کتابخانه پشتیبانی و افزودن کتابخانه ها به محیط توسعه خود راهنمایی می کند.
کتابخانه های پشتیبانی اکنون از طریق مخزن Maven Google در دسترس هستند. ما دیگر از دانلود کتابخانه ها از طریق مدیر SDK پشتیبانی نمی کنیم و این عملکرد به زودی حذف خواهد شد.
انتخاب کتابخانه های پشتیبانی
قبل از افزودن یک کتابخانه پشتیبانی به برنامه خود، تصمیم بگیرید که چه ویژگی هایی را می خواهید شامل شود و پایین ترین نسخه اندرویدی را که می خواهید پشتیبانی کنید. برای اطلاعات بیشتر در مورد ویژگی های ارائه شده توسط کتابخانه های مختلف، به ویژگی های کتابخانه پشتیبانی مراجعه کنید.
افزودن کتابخانه های پشتیبانی
برای استفاده از کتابخانه پشتیبانی، باید وابستگی های مسیر کلاس پروژه برنامه خود را در محیط توسعه خود تغییر دهید. شما باید این روش را برای هر کتابخانه پشتیبانی که می خواهید استفاده کنید انجام دهید.
برای افزودن کتابخانه پشتیبانی به پروژه برنامه خود:
- مخزن Maven Google را در فایل
settings.gradle
پروژه خود قرار دهید. dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
// If you're using a version of Gradle lower than 4.1, you must
// instead use:
//
// maven {
// url 'https://maven.google.com'
// }
}
}
- برای هر ماژولی که میخواهید از کتابخانه پشتیبانی استفاده کنید، کتابخانه را در بلوک
dependencies
فایل build.gradle
ماژول اضافه کنید. به عنوان مثال، برای افزودن کتابخانه core-utils v4، موارد زیر را اضافه کنید: dependencies {
...
implementation "com.android.support:support-core-utils:28.0.0"
}
احتیاط: استفاده از وابستگی های پویا (به عنوان مثال، palette-v7:23.0.+
) می تواند باعث بروز رسانی های غیرمنتظره نسخه و ناسازگاری های رگرسیون شود. توصیه می کنیم که به صراحت یک نسخه کتابخانه (به عنوان مثال، palette-v7:28.0.0
) را مشخص کنید.
استفاده از پشتیبانی کتابخانه API
کلاسهای کتابخانه پشتیبانی که از APIهای چارچوب موجود پشتیبانی میکنند، معمولاً همان نام کلاس فریمورک را دارند اما در بستههای کلاس android.support
قرار دارند یا پسوند *Compat
دارند.
احتیاط: هنگام استفاده از کلاسهای کتابخانه پشتیبانی، مطمئن شوید که کلاس را از بسته مناسب وارد میکنید. به عنوان مثال، هنگام اعمال کلاس ActionBar
:
-
android.support.v7.app.ActionBar
هنگام استفاده از کتابخانه پشتیبانی. -
android.app.ActionBar
هنگام توسعه فقط برای سطح API 11 یا بالاتر.
توجه: پس از گنجاندن کتابخانه پشتیبانی در پروژه برنامه خود، اکیداً توصیه می کنیم که برنامه خود را کوچک کنید، مبهم کنید و برای انتشار بهینه سازی کنید . علاوه بر محافظت از کد منبع شما با مبهم سازی، کوچک کردن کلاس های استفاده نشده را از هر کتابخانه ای که در برنامه خود قرار می دهید حذف می کند، که حجم دانلود برنامه شما را تا حد امکان کوچک نگه می دارد.
راهنمایی بیشتر برای استفاده از برخی ویژگیهای کتابخانه پشتیبانی در کلاسها، راهنماها و نمونههای آموزش برنامهنویس اندروید ارائه شده است. برای اطلاعات بیشتر در مورد کلاسها و روشهای کتابخانه پشتیبانی فردی، بستههای android.support
را در مرجع API ببینید.
تغییرات بیانیه آشکار
اگر با کتابخانه پشتیبانی، سازگاری برنامه موجود خود را به نسخه قبلی API Android افزایش می دهید، حتماً مانیفست برنامه خود را به روز کنید. به طور خاص، باید عنصر android:minSdkVersion
تگ <uses-sdk>
در مانیفست را به شماره نسخه جدید و پایینتر بهروزرسانی کنید، همانطور که در زیر نشان داده شده است:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
تنظیم مانیفست به Google Play میگوید که برنامه شما را میتوان روی دستگاههای دارای Android نسخه 4.0 (سطح API 14) و بالاتر نصب کرد.
اگر از فایل های ساخت Gradle استفاده می کنید، تنظیمات minSdkVersion
در فایل ساخت، تنظیمات مانیفست را لغو می کند.
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
minSdkVersion 16
...
}
...
}
در این حالت، تنظیمات فایل ساخت به Google Play میگوید که نوع ساخت پیشفرض برنامه شما را میتوان بر روی دستگاههای دارای Android 4.1 (سطح API 16) و بالاتر نصب کرد. برای اطلاعات بیشتر در مورد انواع ساخت، نمای کلی سیستم ساخت را ببینید.
توجه: اگر چندین کتابخانه پشتیبانی را شامل میکنید، حداقل نسخه SDK باید بالاترین نسخه مورد نیاز هر یک از کتابخانههای مشخصشده باشد. برای مثال، اگر برنامه شما شامل کتابخانه پشتیبانی ترجیحی v14 و کتابخانه Leanback v17 باشد، حداقل نسخه SDK شما باید 17 یا بالاتر باشد.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-08-27 بهوقت ساعت هماهنگ جهانی."],[],[],null,["**Note:** With the release of Android 9.0 (API level 28) there is\na new version of the support library called\n[AndroidX](/jetpack/androidx) which is part of [Jetpack](/jetpack).\nThe AndroidX library\ncontains the existing support library and also includes the latest Jetpack components.\n\n\u003cbr /\u003e\n\n\nYou can continue to use the support library.\nHistorical artifacts (those versioned 27 and earlier, and packaged as `android.support.*`) will\nremain available on Google Maven. However, all new library development\nwill occur in the [AndroidX](/jetpack/androidx) library.\n\n\u003cbr /\u003e\n\n\nWe recommend using the AndroidX libraries in all new projects. You should also consider\n[migrating](/jetpack/androidx/migrate) existing projects to AndroidX as well.\n\nHow you setup the Android Support Libraries in your development project depends on what features\nyou want to use and what range of Android platform versions you want to support with your\napplication.\n\nThis document guides you through downloading the Support Library package and adding libraries\nto your development environment.\n\nThe support libraries are now available through Google's Maven\nrepository. We no longer support downloading the libraries through the SDK\nManager, and that functionality will be removed soon..\n\nChoosing Support Libraries\n\nBefore adding a Support Library to your application, decide what features you want to include\nand the lowest Android versions you want to support. For more information on the features\nprovided by the different libraries, see\n[Support Library Features](/tools/support-library/features).\n\nAdding Support Libraries\n\nIn order to use a Support Library, you must modify your application's project's\nclasspath dependencies within your development environment. You must perform this procedure for\neach Support Library you want to use.\n\nTo add a Support Library to your application project:\n\n1. Include Google's Maven repository in your project's `settings.gradle` file. \n\n ```groovy\n dependencyResolutionManagement {\n repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)\n repositories {\n google()\n\n // If you're using a version of Gradle lower than 4.1, you must\n // instead use:\n //\n // maven {\n // url 'https://maven.google.com'\n // }\n }\n }\n ```\n2. For each module in which you want to use a Support Library, add the library in the `dependencies` block of the module's `build.gradle` file. For example, to add the v4 core-utils library, add the following: \n\n ```groovy\n dependencies {\n ...\n implementation \"com.android.support:support-core-utils:28.0.0\"\n }\n ```\n\n\n**Caution:** Using dynamic dependencies (for example,\n`palette-v7:23.0.+`) can cause unexpected version updates and\nregression incompatibilities. We recommend that you explicitly specify a\nlibrary version (for example, `palette-v7:28.0.0`).\n\nUsing Support Library APIs\n\nSupport Library classes that provide support for existing framework APIs typically have the\nsame name as framework class but are located in the `android.support` class packages,\nor have a `*Compat` suffix. \n**Caution:** When using classes from the Support Library, be certain you import\nthe class from the appropriate package. For example, when applying the `ActionBar`\nclass:\n\n- `android.support.v7.app.ActionBar` when using the Support Library.\n- `android.app.ActionBar` when developing only for API level 11 or higher.\n\n\n**Note:** After including the Support Library in your application project, we\nstrongly recommend that you [shrink, obfuscate, and optimize\nyour app](/studio/build/shrink-code) for release. In addition to protecting your source code with obfuscation, shrinking\nremoves unused classes from any libraries you include in your application, which keeps the\ndownload size of your application as small as possible.\n\nFurther guidance for using some Support Library features is provided in the Android developer\n[training classes](/training),\n[guides](/guide/components)\nand samples. For more information about the individual Support Library classes and methods, see\nthe [android.support](/reference/android/support/v4/app/package-summary) packages in the API reference.\n\nManifest Declaration Changes\n\nIf you are increasing the backward compatibility of your existing application to an earlier\nversion of the Android API with the Support Library, make sure to update your application's\nmanifest. Specifically, you should update the `android:minSdkVersion`\nelement of the [`\u003cuses-sdk\u003e`](/guide/topics/manifest/uses-sdk-element) tag in the manifest to the new, lower version number, as\nshown below: \n\n```xml\n \u003cuses-sdk\n android:minSdkVersion=\"14\"\n android:targetSdkVersion=\"23\" /\u003e\n```\n\nThe manifest setting tells Google Play that your application can be installed on devices with Android\n4.0 (API level 14) and higher.\n\nIf you are using Gradle build files, the `minSdkVersion` setting in the build file\noverrides the manifest settings. \n\n```groovy\nplugins {\n id 'com.android.application'\n}\n\nandroid {\n ...\n\n defaultConfig {\n minSdkVersion 16\n ...\n }\n ...\n}\n```\n\nIn this case, the build file setting tells Google Play that the default build variant of your\napplication can be installed on devices with Android 4.1 (API level 16) and higher. For more\ninformation about build variants, see\n[Build System Overview](/studio/build).\n\n\n**Note:** If you are including several support libraries, the\nminimum SDK version must be the *highest* version required by any of\nthe specified libraries. For example, if your app includes both the [v14 Preference Support library](/topic/libraries/support-library/features#v14-preference) and the\n[v17 Leanback library](/topic/libraries/support-library/features#v17-leanback), your minimum\nSDK version must be 17 or higher."]]