إعداد مكتبة الدعم
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
ملاحظة: مع إصدار Android 9.0 (المستوى 28 من واجهة برمجة التطبيقات)، يتوفّر إصدار جديد من مكتبة الدعم يُعرف باسم AndroidX وهو جزء من Jetpack.
تحتوي مكتبة AndroidX على مكتبة الدعم الحالية، كما تتضمّن أحدث مكونات Jetpack.
يمكنك مواصلة استخدام مكتبة الدعم.
ستبقى العناصر القديمة (التي تحمل الإصدار 27 أو إصدارًا أقدم، والمحزَّمة على شكل android.support.*
) متاحة على Google Maven. ومع ذلك، سيتم تطوير جميع المكتبات الجديدة في مكتبة AndroidX.
ننصح باستخدام مكتبات AndroidX في جميع المشاريع الجديدة. ننصحك أيضًا بنقل المشاريع الحالية إلى AndroidX.
تعتمد طريقة إعداد "مكتبات دعم Android" في مشروع التطوير على الميزات التي تريد استخدامها ونطاق إصدارات منصة Android التي تريد أن يتوافق تطبيقك معها.
يوضّح هذا المستند كيفية تنزيل حزمة Support Library وإضافة المكتبات إلى بيئة التطوير.
تتوفّر مكتبات الدعم الآن من خلال مستودع Maven من Google. لم نعد نتيح تنزيل المكتبات من خلال "أداة إدارة حزمة تطوير البرامج (SDK)"، وسيتم إزالة هذه الوظيفة قريبًا.
اختيار مكتبات الدعم
قبل إضافة إحدى مكتبات الدعم إلى تطبيقك، حدِّد الميزات التي تريد تضمينها وأدنى إصدارات Android التي تريد أن يتوافق معها التطبيق. لمزيد من المعلومات حول الميزات التي توفّرها المكتبات المختلفة، يُرجى الاطّلاع على ميزات مكتبة الدعم.
إضافة مكتبات الدعم
لاستخدام إحدى "مكتبات الدعم"، عليك تعديل تبعيات مسار الفئة في مشروع تطبيقك ضمن بيئة التطوير. يجب تنفيذ هذا الإجراء لكل حزمة من حِزم Support Library تريد استخدامها.
لإضافة "مكتبة دعم" إلى مشروع تطبيقك، اتّبِع الخطوات التالية:
- أدرِج مستودع 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 الإصدار 4، أضِف ما يلي:
dependencies {
...
implementation "com.android.support:support-core-utils:28.0.0"
}
تنبيه: يمكن أن يؤدي استخدام التبعيات الديناميكية (على سبيل المثال، palette-v7:23.0.+
) إلى حدوث تحديثات غير متوقّعة للإصدارات ومشاكل عدم توافق مع الإصدارات السابقة. ننصحك بتحديد إصدار المكتبة بشكل صريح (على سبيل المثال، palette-v7:28.0.0
).
استخدام واجهات برمجة التطبيقات في "مكتبة الدعم"
تحمل فئات Support Library التي توفّر توافقًا مع واجهات برمجة التطبيقات الحالية في إطار العمل عادةً الاسم نفسه الذي تحمله فئة إطار العمل، ولكنها تقع في حِزم فئات android.support
، أو تحمل اللاحقة *Compat
.
تنبيه: عند استخدام فئات من مكتبة الدعم، تأكَّد من استيراد الفئة من الحزمة المناسبة. على سبيل المثال، عند تطبيق الفئة ActionBar
:
android.support.v7.app.ActionBar
عند استخدام Support Library.
android.app.ActionBar
عند التطوير للمستوى 11 لواجهة برمجة التطبيقات أو مستوى أحدث فقط
ملاحظة: بعد تضمين "مكتبة الدعم" في مشروع تطبيقك، ننصحك بشدة بتقليل حجم تطبيقك وتشويشه وتحسينه قبل إصداره. بالإضافة إلى حماية الرمز المصدر من خلال إخفاء مفاتيح فك التشفير، تعمل عملية تقليل الحجم على إزالة الفئات غير المستخدَمة من أي مكتبات تضمّنها في تطبيقك، ما يحافظ على حجم التنزيل لتطبيقك في أصغر حجم ممكن.
تتوفّر إرشادات إضافية حول استخدام بعض ميزات "مكتبة الدعم" في صفوف التدريب والأدلّة والأمثلة الخاصة بمطوّري تطبيقات Android. لمزيد من المعلومات حول فئات وطُرق Support Library الفردية، راجِع حِزم android.support
في مرجع واجهة برمجة التطبيقات.
التغييرات في بيان البيان
إذا كنت بصدد زيادة التوافق مع الإصدارات القديمة لتطبيقك الحالي مع إصدار أقدم من واجهة برمجة التطبيقات Android باستخدام Support Library، احرص على تعديل ملف البيان الخاص بتطبيقك. على وجه التحديد، يجب تعديل عنصر android:minSdkVersion
في العلامة
<uses-sdk>
في ملف البيان إلى رقم الإصدار الجديد الأصغر، كما هو موضّح أدناه:
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="23" />
يُعلم إعداد البيان Google Play بأنّه يمكن تثبيت تطبيقك على الأجهزة التي تعمل بالإصدار 4.0 من نظام التشغيل Android (المستوى 14 من واجهة برمجة التطبيقات) والإصدارات الأحدث.
إذا كنت تستخدم ملفات إصدار Gradle، سيؤدي الإعداد minSdkVersion
في ملف الإصدار إلى إلغاء إعدادات ملف البيان.
plugins {
id 'com.android.application'
}
android {
...
defaultConfig {
minSdkVersion 16
...
}
...
}
في هذه الحالة، يوضّح إعداد ملف الإصدار على Google Play أنّه يمكن تثبيت صيغة الإصدار التلقائية لتطبيقك على الأجهزة التي تعمل بالإصدار 4.1 من نظام التشغيل Android (المستوى 16 من واجهة برمجة التطبيقات) والإصدارات الأحدث. لمزيد من المعلومات حول صيغ الإنشاء، راجِع نظرة عامة على نظام الإنشاء.
ملاحظة: إذا كنت ستضمّن العديد من مكتبات الدعم، يجب أن يكون الحد الأدنى لإصدار حزمة تطوير البرامج (SDK) هو أعلى إصدار مطلوب من أي من المكتبات المحدّدة. على سبيل المثال، إذا كان تطبيقك يتضمّن كلاً من مكتبة توافق الإصدار 14 من Preference Support ومكتبة Leanback الإصدار 17، يجب أن يكون الإصدار الأدنى من حزمة تطوير البرامج (SDK) هو 17 أو إصدارًا أحدث.
يخضع كل من المحتوى وعيّنات التعليمات البرمجية في هذه الصفحة للتراخيص الموضحّة في ترخيص استخدام المحتوى. إنّ Java و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."]]