<uses-library>
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
注意: Google Play 會使用宣告的 <uses-library>
元素
,篩選掉不符合應用程式的裝置。
程式庫需求如要進一步瞭解篩選功能,請參閱
Google Play 的篩選功能。
- 語法:
-
<uses-library
android:name="string"
android:required=["true" | "false"] />
- 包含於:
-
<application>
- 說明:
-
指定應用程式必須建立連結的共用資料庫。系統可透過這個元素,掌握要在類別載入器中為套件加入的資訊庫程式碼。
所有 android
套件,例如 android.app
android.content
、android.view
和android.widget
,
應用程式會自動連結預設程式庫
下定決心不過,部分套件 (例如 maps
)
而不會自動建立連結的獨立程式庫請參閱所用套件的說明文件,瞭解哪個資料庫包含套件程式碼。
<uses-library>
標記的順序十分重要,會影響類別查詢
和解析度順序有些程式庫可能含有
重複的類別,在這種情況下,系統會優先採用第一個資料庫。
這個元素也會影響應用程式在特定裝置上的安裝情形,
應用程式能否在 Google Play 上架。如果有這個元素及其元素的
android:required
屬性已設為 "true"
,
PackageManager
這個架構 不允許使用者安裝應用程式,除非
使用者的裝置。
下一節將詳細說明 android:required
屬性。
- 屬性:
-
android:name
- 資料庫的名稱。這個名稱是由所用套件的說明文件提供。例如
"android.test.runner"
,這是包含 Android 測試的套件
類別
android:required
-
指出應用程式是否需要
由
android:name
指定的程式庫。
預設值為 "true"
。
導入版本:API 級別 7。
- 導入版本:
- API 級別 1
- 另請參閱:
-
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-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-07-27 (世界標準時間)。"],[],[],null,["# <uses-library\u003e\n\n**Note:** Google Play uses the `\u003cuses-library\u003e` elements declared\nin your app manifest to filter your app from devices that don't meet its\nlibrary requirements. For more information about filtering, see\n[Filters on Google Play](/google/play/filters).\n\nsyntax:\n:\n\n ```xml\n \u003cuses-library\n android:name=\"string\"\n android:required=[\"true\" | \"false\"] /\u003e\n ```\n\ncontained in:\n:\n `\n `[\u003capplication\u003e](/guide/topics/manifest/application-element)`\n `\n\ndescription:\n\n:\n Specifies a shared library that the application must be linked against.\n This element tells the system to include the library's code in the class\n loader for the package.\n\n\n All the `android` packages, such as [android.app](/reference/android/app/package-summary),\n [android.content](/reference/android/content/package-summary), [android.view](/reference/android/view/package-summary), and [android.widget](/reference/android/widget/package-summary),\n are in the default library that all applications are automatically linked\n against. However, some packages, such as `maps`, are\n in separate libraries that aren't automatically linked. Consult the\n documentation for the packages you're using to determine which library\n contains the package code.\n\n\n The order of `\u003cuses-library\u003e` tags is significant. It affects class lookup\n and resolution order when the application loads. Some of the libraries might have\n duplicate classes, and in that case the library that comes first takes priority.\n\n\n This element also affects the installation of the application on a particular device and\n the availability of the application on Google Play. If this element is present and its\n `android:required` attribute is set to `\"true\"`, the\n [PackageManager](/reference/android/content/pm/PackageManager)\n framework won't let a user install the application unless the library is present on the\n user's device.\n\n\n The `android:required` attribute is described in detail in the following section.\n\nattributes:\n:\n\n `android:name`\n :\n The name of the library. The name is provided by the\n documentation for the package you are using. An example of this is\n `\"android.test.runner\"`, a package that contains Android test\n classes.\n\n `android:required`\n :\n Boolean value that indicates whether the application requires the\n library specified by `android:name`.\n\n - `\"true\"`: the application doesn't function without this library. The system doesn't let the application install on a device that doesn't have the library.\n - `\"false\"`: the application uses the library if present, but is designed to function without it if necessary. The system lets the application install, even if the library isn't present. If you use `\"false\"`, you are responsible for checking at runtime that the library is available.\n\n\n To check for a library, you can use reflection to determine\n whether a particular class is available.\n\n\n The default is `\"true\"`.\n\n Introduced in: API level 7.\n\n\nintroduced in:\n: API Level 1\n\nsee also:\n:\n - [PackageManager](/reference/android/content/pm/PackageManager)"]]