- ไวยากรณ์:
-
<uses-native-library android:name="string" android:required=["true" | "false"] />
- มีอยู่ใน
-
<application>
- description:
-
ระบุไลบรารีแบบเนทีฟที่แชร์ซึ่งผู้ให้บริการระบุ ซึ่งแอปพลิเคชันต้องลิงก์ด้วย องค์ประกอบนี้จะบอกให้ระบบทำให้ไลบรารีเนทีฟ เข้าถึงได้สำหรับแพ็กเกจ
ไลบรารี NDK จะเข้าถึงได้โดยค่าเริ่มต้น จึงไม่จำเป็นต้องใช้แท็ก
<uses-native-library>
ไลบรารีที่แชร์แบบเนทีฟที่ไม่ใช่ NDK ซึ่งจัดหาโดยผู้จำหน่ายซิลิคอนหรือผู้ผลิตอุปกรณ์ จะเข้าถึงไม่ได้โดยค่าเริ่มต้นหากแอปกำหนดเป้าหมายเป็น Android 12 (API ระดับ 31) ขึ้นไป โดยจะเข้าถึงไลบรารีได้ก็ต่อเมื่อมีการขออย่างชัดเจนโดยใช้แท็ก
<uses-native-library>
เท่านั้นหากแอปกำหนดเป้าหมายเป็น Android 11 (API ระดับ 30) หรือต่ำกว่า คุณไม่จำเป็นต้องใช้แท็ก
<uses-native-library>
ในกรณีดังกล่าว คุณจะเข้าถึงไลบรารีที่แชร์แบบเนทีฟได้ไม่ว่าจะเป็นไลบรารี NDK หรือไม่ก็ตามองค์ประกอบนี้ยังมีผลต่อการติดตั้งแอปพลิเคชันในอุปกรณ์หนึ่งๆ ด้วย หากมีองค์ประกอบนี้และแอตทริบิวต์
android:required
ตั้งค่าเป็นtrue
เฟรมเวิร์กPackageManager
จะไม่อนุญาตให้ผู้ใช้ติดตั้งแอปพลิเคชัน เว้นแต่ว่าจะมีไลบรารีอยู่ในอุปกรณ์ของผู้ใช้เราจะอธิบายแอตทริบิวต์
android:required
โดยละเอียดในส่วนต่อไปนี้ - แอตทริบิวต์
-
android:name
- ชื่อของไฟล์ไลบรารี
android:required
-
ค่าบูลีนที่ระบุว่าแอปพลิเคชันต้องใช้ไลบรารีที่ระบุโดย
android:name
หรือไม่-
"true"
: แอปพลิเคชันจะทำงานไม่ได้หากไม่มีไลบรารีนี้ ระบบไม่อนุญาตให้ติดตั้งแอปพลิเคชันในอุปกรณ์ที่ไม่มีไลบรารี -
"false"
: แอปพลิเคชันใช้ไลบรารี หากมี แต่ได้รับการออกแบบมาให้ทำงานได้โดยไม่ต้องใช้ไลบรารีหากจำเป็น ระบบจะอนุญาตให้แอปพลิเคชันติดตั้งได้แม้ว่าจะไม่มีไลบรารี ก็ตาม หากคุณใช้"false"
คุณมีหน้าที่รับผิดชอบในการ จัดการการไม่มีไลบรารีอย่างเหมาะสม
ค่าเริ่มต้นคือ
"true"
-
- เปิดตัวใน
- API ระดับ 31
- ดูเพิ่มเติม
<uses-native-library>
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-21 UTC
[null,null,["อัปเดตล่าสุด 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)"]]