- cú pháp:
-
<uses-native-library android:name="string" android:required=["true" | "false"] />
- có trong:
-
<application>
- mô tả:
-
Chỉ định thư viện gốc chia sẻ từ nhà cung cấpphải được liên kết với ứng dụng. Phần tử này yêu cầu hệ thống tạo quyền truy cập vào thư viện gốc cho gói dịch vụ.
Theo mặc định, thư viện NDK có thể truy cập được và do đó không cần có thẻ
<uses-native-library>
.Không thể truy cập theo mặc định các thư viện gốc dùng chung không phải NDK do nhà cung cấp silicon hoặc nhà sản xuất thiết bị cung cấp nếu ứng dụng nhắm mục tiêu Android 12 (API cấp 31) trở lên. Bạn chỉ có quyền truy cập vào thư viện khi chúng được yêu cầu rõ ràng sử dụng thẻ
<uses-native-library>
.Nếu ứng dụng nhắm đến Android 11 (API cấp 30) trở xuống, thì bạn không bắt buộc phải sử dụng thẻ
<uses-native-library>
. Trong trường hợp đó, mọi thư viện gốc dùng chung đều có thể truy cập được, bất kể đó là thư viện NDK.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ể.
android:required
Nếu phần tử này có mặt và thuộc tínhtrue
của phần tử này được đặt thànhPackageManager
, thì khung 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 tệp thư viện.
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.-
"true"
: ứng dụng không hoạt động nếu không có thư viện này. Hệ thống không cho phép cài đặt ứng dụng trên thiết bị không có thư viện. -
"false"
: ứng dụng dùng thư viện (nếu có), nhưng được thiết kế để hoạt động khi không có thư viện nếu cần. Hệ thống cho phép cài đặt ứng dụng, ngay cả khi không có thư viện. Nếu sử dụng"false"
, bạn có trách nhiệm xử lý linh hoạt việc không có thư viện.
Mặc định là
"true"
. -
- ra mắt từ:
- API cấp 31
- xem thêm:
<uses-native-library>
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-08-21 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-08-21 UTC."],[],[],null,["# <uses-native-library\u003e\n\nsyntax:\n:\n\n ```xml\n \u003cuses-native-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 [vendor-provided shared native library](https://source.android.com/devices/tech/config/namespaces_libraries#adding-additional-native-libraries)\n that the application must be linked against. This element tells the system to make the native\n library accessible for the package.\n\n\n NDK libraries are by default accessible and therefore don't require the\n `\u003cuses-native-library\u003e` tag.\n\n\n Non-NDK native shared libraries that are provided by silicon vendors or device manufacturers\n aren't accessible by default if the app targets Android 12 (API level 31) or higher. The\n libraries are accessible only when they are explicitly requested using the\n `\u003cuses-native-library\u003e` tag.\n\n\n If the app targets Android 11 (API level 30) or lower, the\n `\u003cuses-native-library\u003e` tag isn't required. In that case, any native shared\n library is accessible regardless of whether it is an NDK library.\n\n\n This element also affects the installation of the application on a particular device. If this\n element is present and its `android:required` attribute is set to\n `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 file.\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 gracefully handling the absence of the library.\n\n\n The default is `\"true\"`.\n\n\nintroduced in:\n: API level 31\n\nsee also:\n:\n - [PackageManager](/reference/android/content/pm/PackageManager)\n - [\u003cuses-library\u003e](/guide/topics/manifest/uses-library-element)\n [](/guide/topics/manifest/uses-library-element)\n\n [](/guide/topics/manifest/uses-library-element)\n[](/guide/topics/manifest/uses-library-element)"]]