<uses-library> (Thư viện)
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Lưu ý: Google Play sử dụng các phần tử <uses-library>
khai báo trong tệp kê khai ứng dụng để lọc ứng dụng khỏi các thiết bị không đáp ứng yêu cầu về thư viện. Để biết thêm thông tin về cách lọc, hãy xem phần Các bộ lọc trên Google Play.
- cú pháp:
-
<uses-library
android:name="string"
android:required=["true" | "false"] />
- có trong:
-
<application>
- mô tả:
-
Chỉ định một thư viện chia sẻ mà phải được liên kết với ứng dụng.
Phần tử này yêu cầu hệ thống đưa mã của thư viện vào trình tải lớp (class loader) cho gói.
Tất cả các gói android
, chẳng hạn như android.app
, android.content
, android.view
và android.widget
đều nằm trong thư viện mặc định nơi tất cả ứng dụng đều tự động liên kết đến. Tuy nhiên, một số gói (chẳng hạn như maps
) nằm trong các thư viện riêng biệt không được tự động liên kết. Hãy tham khảo tài liệu về các gói bạn đang dùng để xác định thư viện có chứa mã gói đó.
Thứ tự của các thẻ <uses-library>
là rất quan trọng. Thứ tự ảnh hưởng đến quá trình tra cứu lớp và thứ tự giải quyết khi ứng dụng tải. Một số thư viện có thể có các lớp trùng lặp và trong trường hợp đó, thư viện tới trước sẽ được ưu tiên.
Phần tử này cũng ảnh hưởng đến việc cài đặt ứng dụng trên một thiết bị cụ thể cũng như phạm vi cung cấp của ứng dụng trên Google Play. Nếu phần tử này có mặt và thuộc tính android:required
của phần tử này được đặt thành "true"
, thì khung PackageManager
sẽ không cho phép người dùng cài đặt ứng dụng trừ khi thư viện hiện diện trên thiết bị của người dùng.
Thuộc tính android:required
được mô tả chi tiết trong phần sau.
- thuộc tính:
-
android:name
-
Tên của thư viện. Tên này do tài liệu cho gói mà bạn đang sử dụng đưa ra. Ví dụ như đây là
"android.test.runner"
– một gói chứa các lớp kiểm thử Android.
android:required
-
Giá trị Boolean cho biết ứng dụng có cần
thư viện do
android:name
chỉ định hay không.
Mặc định là "true"
.
Ra mắt trong API cấp 7.
- ra mắt từ:
- API cấp 1
- xem thêm:
-
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],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)"]]