ตั้งแต่วันที่ 27 มีนาคม 2025 เป็นต้นไป เราขอแนะนำให้ใช้ android-latest-release
แทน aosp-main
เพื่อสร้างและมีส่วนร่วมใน AOSP โปรดดูข้อมูลเพิ่มเติมที่หัวข้อการเปลี่ยนแปลงใน AOSP
เปิดใช้ VNDK
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
แพ็กเกจการพัฒนาแบบเนทีฟของผู้ให้บริการ (VNDK) กำหนดให้ต้องเปลี่ยนแปลงโค้ดเบสหลายอย่างเพื่อแยกข้อกังวลระหว่างผู้ให้บริการกับระบบ ใช้คำแนะนำต่อไปนี้เพื่อเปิดใช้ VNDK ในโค้ดเบสของผู้ให้บริการ/OEM
สร้างไลบรารีของระบบ
ระบบบิลด์ประกอบด้วยออบเจ็กต์หลายประเภท ซึ่งรวมถึงไลบรารี (ที่ใช้ร่วมกัน แบบคงที่ หรือส่วนหัว) และไบนารี
รูปที่ 1 สร้างไลบรารีของระบบ
core
ไลบรารีใช้โดยอิมเมจระบบในอิมเมจระบบ ไลบรารีเหล่านี้ใช้กับไลบรารี vendor
, vendor_available
, vndk
หรือ vndk-sp
ไม่ได้
cc_library {
name: "libThatIsCore",
...
}
- รูปภาพผู้ให้บริการใช้ไลบรารี
vendor-only
(หรือ proprietary
) ในรูปภาพผู้ให้บริการ
cc_library {
name: "libThatIsVendorOnly",
proprietary: true,
# or: vendor: true, # (for things in AOSP)
...
}
- รูปภาพของผู้ให้บริการใช้คลัง
vendor_available
ในรูปภาพผู้ให้บริการ (อาจมี core
ซ้ำกัน)
cc_library {
name: "libThatIsVendorAvailable",
vendor_available: true,
...
}
vndk
libraries จะใช้โดยรูปภาพผู้ให้บริการในรูปภาพระบบ
cc_library {
name: "libThatIsVndk",
vendor_available: true,
vndk: {
enabled: true,
}
...
}
- รูปภาพจากผู้ให้บริการและรูปภาพของระบบจะใช้ไลบรารี
vndk-sp
โดยอ้อม
cc_library {
name: "libThatIsVndkSp",
vendor_available: true,
vndk: {
enabled: true,
support_system_process: true,
}
...
}
- ทั้งระบบและรูปภาพจากผู้ให้บริการจะใช้ไลบรารี
llndk
cc_library {
name: "libThatIsLlndk",
llndk: {
symbol_file: "libthatisllndk.map.txt"
}
...
}
เมื่อมีการทําเครื่องหมายไลบรารีเป็น vendor_available:true
ระบบจะสร้างไลบรารีดังกล่าว 2 ครั้ง ดังนี้
- 1 ครั้งสำหรับแพลตฟอร์ม (และติดตั้งใน
/system/lib
)
- 1 ครั้งสำหรับผู้ให้บริการ (และติดตั้งลงใน
/vendor/lib
หรือ VNDK APEX)
ไลบรารีเวอร์ชันของผู้ให้บริการสร้างขึ้นด้วย -D__ANDROID_VNDK__
คอมโพเนนต์ระบบส่วนตัวที่อาจมีการเปลี่ยนแปลงอย่างมากใน Android เวอร์ชันในอนาคตจะปิดใช้ด้วย Flag นี้ นอกจากนี้ ไลบรารีต่างๆ จะส่งออกชุดส่วนหัวที่แตกต่างกัน (เช่น liblog
) ตัวเลือกเฉพาะสำหรับตัวแปรผู้ให้บริการของเป้าหมายสามารถระบุได้ในไฟล์ Android.bp
ในส่วนต่อไปนี้
target: { vendor: { … } }
เปิดใช้ VNDK สําหรับโค้ดเบส
วิธีเปิดใช้ VNDK สําหรับโค้ดเบส
- ตรวจสอบการมีสิทธิ์โดยคำนวณขนาดของพาร์ติชัน
vendor.img
และ system.img
ที่จำเป็น
- เปิดใช้
BOARD_VNDK_VERSION=current
คุณสามารถเพิ่มลงใน BoardConfig.mk
หรือสร้างคอมโพเนนต์ด้วย BoardConfig.mk
โดยตรง (เช่น m -j BOARD_VNDK_VERSION=current MY-LIB
)
หลังจากเปิดใช้ BOARD_VNDK_VERSION=current
แล้ว ระบบบิลด์จะบังคับใช้ข้อกำหนดต่อไปนี้เกี่ยวกับ Dependency และส่วนหัว
จัดการ Dependency
ออบเจ็กต์ vendor
ที่ต้องอาศัยคอมโพเนนต์ core
ซึ่งไม่มีอยู่ใน vndk
หรือเป็นออบเจ็กต์ vendor
ต้องได้รับการแก้ไขโดยใช้ตัวเลือกใดตัวเลือกหนึ่งต่อไปนี้
- คุณนำข้อกำหนดนี้ออกได้
- หากคอมโพเนนต์
core
เป็นของ vendor
คุณสามารถทําเครื่องหมายเป็น vendor_available
หรือ vendor
ได้
- การเปลี่ยนแปลงที่ทำให้ออบเจ็กต์หลักเป็นส่วนหนึ่งของ
vndk
อาจส่งต่อไปยัง Google
นอกจากนี้ หากคอมโพเนนต์ core
มีการอ้างอิงคอมโพเนนต์ vendor
คุณต้องเปลี่ยนคอมโพเนนต์ vendor
เป็นคอมโพเนนต์ core
หรือนําการอ้างอิงออกด้วยวิธีอื่น (เช่น นําการอ้างอิงออกหรือย้ายการอ้างอิงไปยังคอมโพเนนต์ vendor
)
คุณต้องนําการพึ่งพาส่วนหัวส่วนกลางออกเพื่อให้ระบบบิลด์ทราบว่าควรสร้างส่วนหัวโดยใส่หรือไม่ใส่ -D__ANDROID_VNDK__
ตัวอย่างเช่น ส่วนหัว libutils เช่น utils/StrongPointer.h
จะยังคงเข้าถึงได้โดยใช้ไลบรารีส่วนหัว libutils_headers
ส่วนส่วนหัวบางรายการ (เช่น unistd.h
) จะรวมแบบทรานซิทีฟไม่ได้อีกต่อไป แต่สามารถรวมในเครื่องได้
สุดท้ายนี้ เราได้ย้ายส่วนสาธารณะของ private/android_filesystem_config.h
ไปไว้ที่ cutils/android_filesystem_config.h
แล้ว หากต้องการจัดการส่วนหัวเหล่านี้ ให้ทําอย่างใดอย่างหนึ่งต่อไปนี้
- นำการพึ่งพา
private/android_filesystem_config.h
ออกโดยแทนที่มาโคร AID_*
ทั้งหมดด้วยการเรียกใช้ getgrnam
/
getpwnam
หากเป็นไปได้ เช่น
(uid_t)AID_WIFI
เปลี่ยนเป็น
getpwnam("wifi")->pw_uid
(gid_t)AID_SDCARD_R
เปลี่ยนเป็น
getgrnam("sdcard_r")->gr_gid
ดูรายละเอียดได้ที่
private/android_filesystem_config.h
- สำหรับ AIS ที่มีการฮาร์ดโค้ด ให้ใส่
cutils/android_filesystem_config.h
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา Java และ OpenJDK เป็นเครื่องหมายการค้าหรือเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-27 UTC
[[["เข้าใจง่าย","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"]],["อัปเดตล่าสุด 2025-07-27 UTC"],[],[],null,["# Enable VNDK\n\nThe Vendor Native Development Kit (VNDK) requires several changes to a codebase to separate\nconcerns between vendor and system. Use the following guide to enable VNDK in a vendor/OEM\ncodebase.\n\nBuild system libraries\n----------------------\n\nThe build system contains several types of objects including libraries\n(shared, static, or header) and binaries.\n\n**Figure 1.** Build system libraries.\n\n- `core` libraries are used by the system image, on the system image. These libraries can't be used by `vendor`, `vendor_available`, `vndk`, or `vndk-sp` libraries. \n\n ```carbon\n cc_library {\n name: \"libThatIsCore\",\n ...\n }\n ```\n- `vendor-only` (or `proprietary`) libraries are used by the vendor image, on the vendor image. \n\n ```carbon\n cc_library {\n name: \"libThatIsVendorOnly\",\n proprietary: true,\n # or: vendor: true, # (for things in AOSP)\n ...\n }\n ```\n- `vendor_available` libraries are used by the vendor image, on the vendor image (may contain duplicates of `core`). \n\n ```carbon\n cc_library {\n name: \"libThatIsVendorAvailable\",\n vendor_available: true,\n ...\n }\n ```\n- `vndk` libraries are used by the vendor image, on the system image. \n\n ```carbon\n cc_library {\n name: \"libThatIsVndk\",\n vendor_available: true,\n vndk: {\n enabled: true,\n }\n ...\n }\n ```\n- `vndk-sp` libraries are used by the vendor image, and also by the system image indirectly. \n\n ```carbon\n cc_library {\n name: \"libThatIsVndkSp\",\n vendor_available: true,\n vndk: {\n enabled: true,\n support_system_process: true,\n }\n ...\n }\n ```\n- `llndk` libraries are used by both the system and vendor images. \n\n ```carbon\n cc_library {\n name: \"libThatIsLlndk\",\n llndk: {\n symbol_file: \"libthatisllndk.map.txt\"\n }\n ...\n }\n ```\n\nWhen a lib is marked as `vendor_available:true`, it's built\ntwice:\n\n- Once for platform (and thus installed to `/system/lib`)\n- Once for vendor (and thus installed to `/vendor/lib` or VNDK APEX)\n\nThe vendor versions of libs are built with `-D__ANDROID_VNDK__`.\nPrivate system components that may change significantly in future versions of\nAndroid are disabled with this flag. In addition, different libraries export a\ndifferent set of headers (such as `liblog`). Options specific to a\nvendor variant of a target can be specified in an `Android.bp` file\nin: \n\n```text\ntarget: { vendor: { … } }\n```\n\nEnable VNDK for a codebase\n--------------------------\n\nTo enable the VNDK for a codebase:\n\n1. Determine eligibility by calculating the required sizes of `vendor.img` and `system.img` partitions.\n2. Enable `BOARD_VNDK_VERSION=current`. You can add to `BoardConfig.mk` or build components with it directly (for example, `m -j BOARD_VNDK_VERSION=current `\u003cvar translate=\"no\"\u003eMY-LIB\u003c/var\u003e).\n\nAfter enabling `BOARD_VNDK_VERSION=current`, the build system\nenforces the following dependency and header requirements.\n\n### Manage dependencies\n\nA `vendor` object that depends on a `core` component\nthat doesn't exist in `vndk` or as a `vendor` object\nmust be resolved using one of the following options:\n\n- The dependency can be removed.\n- If the `core` component is owned by `vendor`, it can be marked as `vendor_available` or `vendor`.\n- A change making the core object part of the `vndk` may be upstreamed to Google.\n\nIn addition, if a `core` component has dependencies on a\n`vendor` component, the `vendor` component must be made\ninto a `core` component **or** the dependency must be\nremoved in another way (for example, by removing the dependency or by moving the\ndependency into a `vendor` component).\n\n### Manage headers\n\nGlobal header dependencies must be removed to enable the build system to know\nwhether to build the headers with or without `-D__ANDROID_VNDK__`.\nFor example, libutils headers such as `utils/StrongPointer.h` can\nstill be accessed using the header library\n[`libutils_headers`](https://android.googlesource.com/platform/system/core/+/android16-release/libutils/include/utils).\n\nSome headers (such as `unistd.h`) can no longer be included transitively\nbut can be included locally.\n\nFinally, the public part of `private/android_filesystem_config.h`\nhas been moved to `cutils/android_filesystem_config.h`. To manage\nthese headers, do one of the following:\n\n- Remove the dependency to `private/android_filesystem_config.h` by replacing all `AID_*` macros with [getgrnam](http://man7.org/linux/man-pages/man3/getgrnam.3.html)/ [getpwnam](http://man7.org/linux/man-pages/man3/getpwnam.3.html) calls if possible. For example:\n - `(uid_t)AID_WIFI` becomes `getpwnam(\"wifi\")-\u003epw_uid`.\n - `(gid_t)AID_SDCARD_R` becomes `getgrnam(\"sdcard_r\")-\u003egr_gid`.\n\n For details, refer to [private/android_filesystem_config.h](https://android.googlesource.com/platform/system/core/+/android16-release/libcutils/include/private/android_filesystem_config.h).\n- For hard-coded AIS, include `cutils/android_filesystem_config.h`."]]