<使用库>
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
注意: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"
:如果没有此库,则应用将无法正常运行。系统不允许将应用安装在没有此库的设备上。
-
"false"
:如果此库存在,应用会使用此库,但必要时也可在没有此库的情况下运行。
系统允许安装应用,即使不存在此库也是如此。如果您使用 "false"
,则需要在运行时检查有没有此库。
要检查库,您可以使用反射来确定有没有特定类。
默认值为 "true"
。
此项为 API 级别 7 中的新增配置。
- 引入于:
- API 级别 1
- 另请参阅:
-
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):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"]],["最后更新时间 (UTC):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)"]]