サポート ライブラリ
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
注: Android 9.0(API レベル 28)のリリース以降、Jetpack の一部として AndroidX という新しいバージョンのサポート ライブラリが導入されました。AndroidX ライブラリには既存のサポート ライブラリのほか、最新の Jetpack コンポーネントも含まれています。
サポート ライブラリは引き続きご利用いただけます。過去のアーティファクト(バージョン 27 以前で android.support.*
としてパッケージ化されたもの)は、Google Maven で引き続き利用できます。ただし、新しいライブラリ開発はすべて AndroidX ライブラリ内で行うことになります。
すべての新しいプロジェクトに AndroidX ライブラリを使用することをおすすめします。また、既存のプロジェクトを AndroidX に移行することもご検討ください。
複数の API バージョンをサポートするアプリを開発するときは、以前のバージョンの Android に新しい機能を提供したり、同等の機能にスムーズに戻したりする標準的な方法が必要な場合があります。以前のバージョンのプラットフォームを処理するコードを構築する代わりに、これらのライブラリを利用してその互換性レイヤを提供できます。さらに、サポート ライブラリには標準のフレームワーク API では利用できない便利なクラスや機能が追加され、より多くのデバイスにまたがる開発やサポートが容易になっています。
元々はアプリ向けの単一バイナリ ライブラリであった Android サポート ライブラリが、アプリ開発用のライブラリ スイートに進化しました。現在、これらのライブラリの多くは、必須ではありませんがアプリ開発の一部として強く推奨されています。
このドキュメントでは、サポート ライブラリのコンポーネントや、アプリでサポート ライブラリを効果的に使用する方法を理解するのに役立つサポート ライブラリの概要を説明します。
注意: サポート ライブラリ リリース 26.0.0(2017 年 7 月)以降、ほとんどのサポート ライブラリでサポートされる最小 API レベルが、多くのライブラリ パッケージで Android 4.0(API レベル 14)まで上がっています。対象
詳細については、バージョン サポートとパッケージ
名前。
サポート ライブラリの用途
サポート ライブラリの用途はいくつかあります。以前のバージョンのプラットフォームに対して下位互換性があるクラスは、そのうちのひとつにすぎません。アプリでサポート ライブラリを使用する方法の一覧を以下に示します。
-
新しい API 向けの下位互換性 - 多数のサポート ライブラリが、新しいフレームワーク クラスとメソッド向けに下位互換性を提供しています。たとえば、
Fragment
サポートクラスを使用すると、Android 3.0(API レベル 11)より前のバージョンを搭載しているデバイス上でフラグメントがサポートされます。
-
便利なヘルパークラス - サポート ライブラリは、特にユーザー インターフェースの開発に使用される複数のヘルパークラスを提供します。対象
たとえば、
RecyclerView
クラスは
非常に長いリストを表示、管理するためのインターフェース ウィジェット。
API レベル 7 以降の Android バージョンが必要です。
-
デバッグとユーティリティ - アプリに組み込んだコード以外のユーティリティを提供する機能が多数用意されています。たとえば、メソッド入力に対するコード lint チェックを強化した
support-annotations
ライブラリや、65,536 を超えるメソッドを使用するアプリの構成、配信を行うための Multidex サポートなどがあります。
サポート ライブラリとフレームワーク API の使用上の相違点
サポート ライブラリは、Android フレームワークの API によく似たクラスとメソッドを提供します。このことから、フレームワーク バージョンの API または同等のサポート ライブラリを使用する必要があるのではないかと思われるかもしれません。フレームワーク API の代わりにサポート ライブラリ クラスを使用するべき状況についてのガイドラインは次のとおりです。
-
特定の機能の互換性 - 以前のバージョンのプラットフォームを実行しているデバイスで最新のプラットフォーム機能をサポートする必要がある場合は、サポート ライブラリの同等のクラスとメソッドを使用してください。
-
関連ライブラリ機能の互換性 - 高度なサポート ライブラリ クラスの場合、1 つまたは複数の追加サポート ライブラリ クラスに依存している可能性があります。そのため、依存関係を満たすようにサポート ライブラリ クラスを使用する必要があります。たとえば、
ViewPager
サポートクラスの場合、FragmentPagerAdapter
サポートクラスまたは FragmentStatePagerAdapter
サポートクラスとともに使用する必要があります。
-
一般的なデバイスの互換性 - アプリで使用する特定のプラットフォーム機能に関して下位互換性を確保する予定がない場合も、アプリ内でサポート ライブラリ クラスを使用することをおすすめします。たとえば、フレームワークの
Activity
クラスの代わりに ActivityCompat
を使用すると、Android 6.0(API レベル 23)で導入された新しいパーミッション モデルを組み込むなど、後で新しい機能を利用できます。
プラットフォーム API クラスの互換実装を実現するサポート ライブラリ クラスは、場合によっては、ホストデバイスのプラットフォーム バージョンの制限により、最新リリースで利用できる機能の一部を実現できないことがあります。この場合、サポート ライブラリ クラスはグレースフル デグラデーションを実行するように設計されており、現在のプラットフォーム API のすべての機能やデータを提供しないことがあります。このため、使用するライブラリ クラスとメソッドについてリファレンス ドキュメントを確認し、アプリでサポートされる最も古いバージョンのプラットフォームを実行しているデバイスで徹底的にテストする必要があります。
注: サポート ライブラリは、すべてのフレームワーク API に対して同等のクラスやメソッドを提供するわけではありません。場合によっては、フレームワーク メソッドの呼び出しを明示的な SDK バージョン チェックと統合し、デバイスで利用できないメソッドを処理するための代替コードを提供する必要があります。コードでバージョン チェックを使用する方法の詳細については、異なるプラットフォーム バージョンのサポートをご覧ください。
バージョン サポートとパッケージ名
サポート ライブラリ パッケージによっては、最初にサポートしていた API の最小レベルを v# 表記で示したパッケージ名を持つものがあります(support-v4 など)。サポート ライブラリ バージョン 26.0.0(2017 年 7 月リリース)以降、すべてのサポート ライブラリ パッケージを対象に、サポートされる最小 API レベルが Android 4.0(API レベル 14)に変更されました。このため、サポート ライブラリの最近のリリースを使用する場合は、v# パッケージ表記が最小の API サポートレベルを示しているとは限りません。最近のリリースで行われたこの変更は、v4 と v7 のライブラリ パッケージでサポートされる API の最小レベルが本質的に同等であることも意味します。たとえば、support-v4 と support-v7 のどちらのパッケージも、26.0.0 リリース以降のサポート ライブラリに対して最小 API レベル 14 をサポートします。
サポート ライブラリのリリース バージョン
サポート ライブラリのリリース バージョン(24.2.0 や 25.0.1 など)は、そのリリースのすべてのライブラリでサポートされている最小 API レベルとは異なります。リリース バージョン番号は、ビルドの対象となったプラットフォーム API のバージョンを示します。つまり、そのバージョンのライブラリに含まれている最新の API です。
具体的には、通常はリリース バージョン番号の最初の部分(バージョン 24.2.0 の場合は 24)が、リリース時に使用可能であったプラットフォーム API のバージョンに対応しています。サポート ライブラリのリリース バージョン レベルは、その API レベルのいくつかの機能が組み込まれていることを意味しますが、新しいプラットフォーム API バージョンでリリースされたすべての機能と互換性があるとは限りません。
ライブラリの依存関係
Android サポート ライブラリ スイートの多くのライブラリは、1 つ以上のライブラリと依存関係があります。たとえば、ほとんどすべてのサポート ライブラリには support-compat
パッケージとの依存関係があります。通常は Gradle ビルドツールが自動的に従属ライブラリを追加してライブラリの依存関係を管理するため、サポート ライブラリの依存関係を気にする必要はありません。
アプリに含まれているライブラリとその依存関係を確認するには、アプリ開発プロジェクトのビルドルートで次のコマンドを実行して、Android サポート ライブラリや他のライブラリを含むプロジェクトの依存関係のレポートを取得します。
gradle -q dependencies your-app-project:dependencies
Gradle を使用して開発プロジェクトにサポート ライブラリを追加する方法については、サポート ライブラリのセットアップをご覧ください。Gradle の使用について詳しくは、ビルドを設定するをご覧ください。
また、すべての Android サポート ライブラリが、最近のリリース(Android 4.0(API レベル 14)以降)のプラットフォームのベースレベルに対して依存関係があります。
このページのコンテンツやコードサンプルは、コンテンツ ライセンスに記載のライセンスに従います。Java および OpenJDK は Oracle および関連会社の商標または登録商標です。
最終更新日 2024-08-23 UTC。
[[["わかりやすい","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"]],["最終更新日 2024-08-23 UTC。"],[],[],null,["# Support Library\n\n**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\n\nWhen developing apps that support multiple API versions, you may want a\nstandard way to provide newer features on earlier versions of Android or\ngracefully fall back to equivalent functionality. Rather than building code\nto handle earlier versions of the platform, you can leverage these libraries\nto provide that compatibility layer. In addition, the Support Libraries\nprovide additional convenience classes and features not available in the\nstandard Framework API for easier development and support across more\ndevices.\n\n\nOriginally a single binary library for apps, the Android Support Library has\nevolved into a suite of libraries for app development. Many of these\nlibraries are now a strongly recommended, if not essential, part of app\ndevelopment.\n\n\nThis document provides an overview of the support library to help you\nunderstand its components and how to use it effectively in your app.\n\n\n**Caution:** Starting with Support Library release 26.0.0\n(July 2017), the minimum supported API level across most support libraries\nhas increased to Android 4.0 (API level 14) for most library packages. For\nmore information, see [Version Support and Package\nNames](#api-versions) on this page.\n\nUses for the Support Libraries\n------------------------------\n\n\nThere are a few distinct uses for the support libraries. Backward\ncompatibility classes for earlier versions of the platform is just one of\nthem. Here is a more complete list of ways you can use the support libraries\nin your app:\n\n- **Backward Compatibility for newer APIs** - A large amount of the support libraries provide backward compatibility for newer framework classes and methods. For example, the [Fragment](/reference/androidx/fragment/app/Fragment) support class provides support for fragments on devices running versions earlier than Android 3.0 (API level 11).\n- **Convenience and Helper Classes** - The support libraries provides a number of helper classes, particularly for user interface development. For example the [RecyclerView](/reference/androidx/recyclerview/widget/RecyclerView) class provides a user interface widget for displaying and managing very long lists, useable on versions of Android from API level 7 and up.\n- **Debugging and Utilities** - There are a number of features that provide utility beyond code you incorporate into your app, including the [`support-annotations`](/studio/write/annotations) library for improved code lint checks on method inputs and [Multidex support](/studio/build/multidex) for configuring and distributing apps with over 65,536 methods.\n\nUsing Support versus Framework APIs\n-----------------------------------\n\n\nSupport Libraries provide classes and methods that closely resemble APIs in\nthe Android Framework. Upon discovering this, you may wonder if you should\nuse the framework version of the API or the support library equivalent. Here\nare the guidelines for when you should use support library classes in place\nof Framework APIs:\n\n- **Compatibility for a Specific Feature** - If you want to support a recent platform feature on devices that are running earlier versions of the platform, use the equivalent classes and methods from the support library.\n- **Compatibility for Related Library Features** - More sophisticated support library classes may depend on one or more additional support library classes, so you should use support library classes for those dependencies. For example, the [ViewPager](/reference/androidx/viewpager/widget/ViewPager) support class should be used with [FragmentPagerAdapter](/reference/androidx/fragment/app/FragmentPagerAdapter) or the [FragmentStatePagerAdapter](/reference/androidx/fragment/app/FragmentStatePagerAdapter) support classes.\n- **General Device Compatibility** - If you do not have a specific platform feature you intend to use with your app in a backward compatible way, it is still a good idea to use support library classes in your app. For example, you may want to use [ActivityCompat](/reference/androidx/core/app/ActivityCompat) in place of the framework [Activity](/reference/android/app/Activity) class, so you can take advantage of newer features later on, such as incorporating the new permissions model introduced in Android 6.0 (API level 23).\n\n\nSupport Library classes that provide a compatible implementation of platform\nAPI classes may not be able to provide the full set of functionality\navailable in the latest release, due to the limitations of the host device\nplatform version. In these cases, Support Library classes are designed to\ndegrade gracefully, and may not provide the all the functionality or data of\nthe current, platform API. For this reason, you should review the reference\ndocumentation for the library classes and methods you use, and thoroughly\ntest on devices running the earliest version of the platform supported by\nyour app.\n\n\n**Note:** The support libraries do not provide equivalent\nclasses and methods for each framework API. In some cases, you may need to\nwrap a framework method call with an explicit SDK version check and provide\nalternative code to handle methods not available on a device. For more\ninformation on using version checks in your code, see [Supporting Different\nPlatform Versions](/training/basics/supporting-devices/platforms).\n\nVersion Support and Package Names\n---------------------------------\n\n\nSome of the Support Library packages have package names to indicate the\nminimum level of the API they originally supported,\nusing a v# notation, such as the\nsupport-v4 package. Starting with Support Library version 26.0.0 (released in\nJuly 2017), the minimum supported API level has changed to Android 4.0 (API\nlevel 14) for all support library packages. For this reason, when working with\nany recent release of the support library, you should not assume that the\nthe *v#* package notation indicates a minimum API support level.\nThis change in recent releases also means that library packages with the v4\nand v7 are essentially equivalent in the minimum level of API they support.\nFor example, the support-v4 and the support-v7 package both support a minimum\nAPI level of 14, for releases of the Support Library from 26.0.0 and higher.\n\n### Support Library Release Versions\n\n\nThe [release version](/topic/libraries/support-library/revisions) of the Support Library, such as 24.2.0 or 25.0.1, is\ndifferent from the minimum API level supported by any library in that\nrelease.The release version number indicates which version of the platform\nAPI it was built against, and therefore, what the most recent APIs *may be\nincluded* in this version of the libraries.\n\n\nSpecifically, the first section of the release version number, for example\nthe 24 in version 24.2.0, generally corresponds with the version of the\nplatform API available when it was released. The release version level of the\nsupport library indicates it incorporates *some* features of that API\nlevel, but you should not assume it provides compatibility with *all*\nfeatures released in the new platform API version.\n\nLibrary Dependencies\n--------------------\n\n\nMost libraries in the Android Support Library suite have some dependency on\none or more libraries. For example, nearly all support libraries have a\ndependency on the `support-compat` package. In general, you do not\nneed to worry about support library dependencies, because the gradle build\ntool manages library dependencies for you, by automatically including\ndependent libraries.\n\n\nIf you want to see what libraries and library dependencies are included in\nyour app, run the following command at the build root of your app development\nproject to get a report of the dependencies for that project, including\nAndroid Support Libraries and other libraries: \n\n```\ngradle -q dependencies your-app-project:dependencies\n```\n\n\nFor more information about adding support libraries to your development\nproject using Gradle, see [Support\nLibrary Setup](/topic/libraries/support-library/setup). For more information about working with Gradle, see\n[Configure\nYour Build](/studio/build).\n\n\nNote that *all* Android Support Libraries also depend on some base level\nof the platform, for recent releases, that is Android 4.0 (API level 14) or\nhigher."]]