- 語法:
-
<uses-native-library android:name="string" android:required=["true" | "false"] />
- 包含於:
-
<application>
- 說明:
-
指定應用程式必須與之連結的 供應商提供的共享原生程式庫。這個元素會告知系統是否能存取套件的原生資料庫。
根據預設,NDK 程式庫可以存取,因此不需要
<uses-native-library>
標記。根據預設,如果應用程式是以 Android 12 (API 級別 31) 以上為目標版本,則無法存取由晶片供應商或裝置製造商提供的非 NDK 原生共用程式庫。只有使用
<uses-native-library>
標記明確要求時,才能存取這些程式庫。如果應用程式指定 Android 11 (API 級別 30) 以下為目標版本,則不需要
<uses-native-library>
標記。在這種情況下,任何原生共享程式庫均可存取,無論其是否為 NDK 程式庫。這個元素也會影響應用程式在特定裝置上的安裝情形。如果這個元素存在且其
android:required
屬性設為true
,PackageManager
架構就不允許使用者安裝應用程式,除非使用者的裝置上存在這個程式庫。下一節將詳細說明
android:required
屬性。 - 屬性:
- 導入版本:
- API 級別 31
- 另請參閱:
<uses-native-library>
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-08-21 (世界標準時間)。
[null,null,["上次更新時間:2025-08-21 (世界標準時間)。"],[],[],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)"]]