สคริปต์ ndk-build
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
สคริปต์ ndk-build
จะสร้างโปรเจ็กต์ที่ใช้บิลด์แบบ Make ของ NDK
ระบบ มีเอกสารประกอบที่เฉพาะเจาะจงมากขึ้นเกี่ยวกับ
Android.mk และ
ใช้การกำหนดค่า Application.mk แล้ว
โดย ndk-build
ภายใน
การเรียกใช้สคริปต์ ndk-build
เทียบเท่ากับการเรียกใช้คำสั่งต่อไปนี้:
$GNUMAKE -f <ndk>/build/core/build-local.mk
<parameters>
$GNUMAKE
ชี้ไปที่ GNU Make 3.81 ขึ้นไป และ
<ndk>
ชี้ไปที่ไดเรกทอรีการติดตั้ง NDK คุณสามารถใช้
ข้อมูลนี้เพื่อเรียกใช้ ndk-build จากสคริปต์เชลล์อื่นๆ หรือแม้แต่สคริปต์ของคุณเอง
สร้างไฟล์
เรียกใช้จากบรรทัดคำสั่ง
สคริปต์ ndk-build
อยู่ในไดเรกทอรีการติดตั้ง NDK ระดับบนสุด เพื่อเรียกใช้
จากบรรทัดคำสั่ง ให้เรียกใช้ขณะอยู่ในหรือภายใต้ไดเรกทอรีโปรเจ็กต์แอปพลิเคชัน
เช่น
$ cd <project>
$ <ndk>/ndk-build
ในตัวอย่างนี้ <project>
ชี้ไปที่
ไดเรกทอรีรากของโปรเจ็กต์ และ <ndk>
คือไดเรกทอรีที่
ที่คุณติดตั้ง NDK
ตัวเลือก
พารามิเตอร์ทั้งหมดของ ndk-build จะส่งไปยัง GNU make
ที่สำคัญโดยตรง
ที่เรียกใช้สคริปต์บิลด์ NDK รวม ndk-build
และ
ตัวเลือกในแบบฟอร์ม ndk-build <option>
เช่น
$ ndk-build clean
โดยมีตัวเลือกให้เลือกดังต่อไปนี้
-
clean
-
นำไบนารีที่สร้างขึ้นก่อนหน้านี้ออก
หมายเหตุ: ใน Mac OS X ให้ใช้ ndk-build clean
กับ
การดำเนินการพร้อมกันจำนวนมากอาจทำให้เกิดข้อผิดพลาดในบิลด์
มีข้อความต่อไปนี้:
rm: fts_read: No such file or directory
หากไม่ต้องการให้เกิดปัญหานี้ โปรดอย่าใช้ -jN
แป้นกดร่วม หรือเลือกค่าที่น้อยกว่าสำหรับ N
เช่น 2
-
V=1
-
เปิดบิลด์ และแสดงคำสั่งของบิลด์
-
-B
-
บังคับให้สร้างใหม่เสร็จสมบูรณ์
-
-B V=1
-
บังคับให้สร้างใหม่เสร็จสมบูรณ์ และแสดงคำสั่งของบิลด์
-
NDK_LOG=1
-
แสดงข้อความบันทึก NDK ภายใน (ใช้สำหรับการแก้ไขข้อบกพร่องของ NDK)
-
NDK_DEBUG=1
-
บังคับบิลด์ที่แก้ไขข้อบกพร่องได้ (ดูตาราง 1)
-
NDK_DEBUG=0
-
บังคับใช้บิลด์รุ่น (ดูตาราง 1)
-
NDK_HOST_32BIT=1
-
ใช้ Toolchain ในโหมด 32 บิตเสมอ
-
NDK_APPLICATION_MK=<file>
-
สร้าง โดยใช้ไฟล์
Application.mk
เฉพาะที่ชี้ไปยัง
ตัวแปร NDK_APPLICATION_MK
-
-C <project>
-
สร้างโค้ดเนทีฟสำหรับเส้นทางโปรเจ็กต์ซึ่งอยู่ที่
<project>
มีประโยชน์หากคุณไม่ต้องการcd
ที่เครื่องอ่านบัตรดังกล่าว
บิลด์ที่แก้ไขข้อบกพร่องได้กับบิลด์ที่เผยแพร่ได้
ใช้ตัวเลือก NDK_DEBUG
และในบางกรณี
AndroidManifest.xml
เพื่อระบุการแก้ไขข้อบกพร่องหรือเปิดตัวบิลด์
พฤติกรรมที่เกี่ยวกับการเพิ่มประสิทธิภาพ และการรวมสัญลักษณ์ ตาราง 1 แสดงฟังก์ชัน
ผลลัพธ์ของชุดค่าผสมที่เป็นไปได้แต่ละรายการ
ตาราง 1 ผลลัพธ์ของ NDK_DEBUG
(บรรทัดคำสั่ง) และ
ชุดค่าผสม android:debuggable
(ไฟล์ Manifest)
การตั้งค่าไฟล์ Manifest | NDK_DEBUG=0 | NDK_DEBUG=1 | ไม่ได้ระบุ NDK_DEBUG
|
android:debuggable="จริง" | แก้ไขข้อบกพร่อง สัญลักษณ์; เพิ่มประสิทธิภาพ*1
| แก้ไขข้อบกพร่อง สัญลักษณ์; ไม่ได้เพิ่มประสิทธิภาพ*2 | (เหมือนกับ NDK_DEBUG=1)
|
android:debuggable="เท็จ" | เผยแพร่ สัญลักษณ์; เพิ่มประสิทธิภาพ
| เผยแพร่ สัญลักษณ์; ไม่ได้เพิ่มประสิทธิภาพ | เผยแพร่ ไม่มีสัญลักษณ์
เพิ่มประสิทธิภาพ*3 |
*1: มีประโยชน์ในการทำโปรไฟล์
*2: ค่าเริ่มต้นสำหรับการเรียกใช้ ndk-gdb
*3: โหมดเริ่มต้น
หมายเหตุ: `NDK_DEBUG=0` มีค่าเทียบเท่ากับ
"APP_OPTIM=release" และคอมไพล์ด้วย "-O2" `NDK_DEBUG=1` เทียบเท่ากับ
"APP_OPTIM=debug" ใน "Application.mk" และคอมไพล์ด้วย "-O0"
ดูข้อมูลเพิ่มเติมเกี่ยวกับ "APP_OPTIM" ได้ที่
Application.mk
ตัวอย่างเช่น ไวยากรณ์ในบรรทัดคำสั่งมีดังนี้
$ ndk-build NDK_DEBUG=1
ข้อกำหนด
คุณต้องมี GNU Make 4 เพื่อใช้ ndk-build หรือ NDK โดยทั่วไป NDK ประกอบด้วย
สำเนา GNU Make เองและจะใช้สำเนานั้นเว้นแต่คุณจะตั้งค่า $GNUMAKE
ตัวแปรสภาพแวดล้อมที่ชี้ไปยังแบรนด์ที่ไม่เหมาะสม
ฐานข้อมูลการคอมไพล์ JSON
ใน NDK r18 ขึ้นไป ndk-build สามารถสร้าง
ฐานข้อมูลการคอมไพล์ JSON
คุณจะใช้ ndk-build compile_commands.json
เพื่อสร้างฐานข้อมูลก็ได้
โดยไม่สร้างโค้ด หรือndk-build GEN_COMPILE_COMMANDS_DB=true
หากคุณ
ต้องการสร้างและสร้างฐานข้อมูลเป็นผลข้างเคียง
ตัวอย่างเนื้อหาและโค้ดในหน้าเว็บนี้ขึ้นอยู่กับใบอนุญาตที่อธิบายไว้ในใบอนุญาตการใช้เนื้อหา 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,["# The ndk-build script\n\nThe `ndk-build` script builds projects that use the NDK's Make-based build\nsystem. There is more specific documentation for the\n[Android.mk](/ndk/guides/android_mk) and\n[Application.mk](/ndk/guides/application_mk) configuration used\nby `ndk-build`.\n\nInternals\n---------\n\nRunning the `ndk-build` script is equivalent to running the following command: \n\n```\n$GNUMAKE -f \u003cndk\u003e/build/core/build-local.mk\n\u003cparameters\u003e\n```\n\n`$GNUMAKE` points to GNU Make 3.81 or later, and\n`\u003cndk\u003e` points to your NDK installation directory. You can use\nthis information to invoke ndk-build from other shell scripts, or even your own\nmake files.\n\nInvoke from the command line\n----------------------------\n\nThe `ndk-build` script lives in the top level NDK installation directory. To run it\nfrom the command line, invoke it while in or under your application project directory.\nFor example: \n\n```\n$ cd \u003cproject\u003e\n$ \u003cndk\u003e/ndk-build\n```\n\nIn this example, `\u003cproject\u003e` points to your\nproject's root directory, and `\u003cndk\u003e` is the directory where\nyou installed the NDK.\n\n### Options\n\nAll parameters to ndk-build are passed directly to the underlying GNU `make`\ncommand that runs the NDK build scripts. Combine `ndk-build` and\noptions in the form `ndk-build \u003coption\u003e`. For example: \n\n```\n$ ndk-build clean\n```\n\n\nThe following options are available:\n\n\n`clean`\n\n: Remove any previously generated binaries.\n **Note:** On Mac OS X, running `ndk-build clean` with a\n high number of [parallel executions](https://www.gnu.org/software/make/manual/html_node/Parallel.html) may result in a build error that\n includes the following message:\n\n ```\n rm: fts_read: No such file or directory\n ```\n\n\n To avoid this issue, consider not using the `-j`\u003cvar translate=\"no\"\u003eN\u003c/var\u003e\n modifier or selecting a smaller value for \u003cvar translate=\"no\"\u003eN\u003c/var\u003e, such as 2.\n\n\n`V=1`\n:\n Launch build, and display build commands.\n\n\n`-B`\n:\n Force a complete rebuild.\n\n\n`-B V=1`\n:\n Force a complete rebuild, and display build commands.\n\n\n`NDK_LOG=1`\n:\n Display internal NDK log messages (used for debugging the NDK itself).\n\n\n`NDK_DEBUG=1`\n:\n Force a debuggable build (see [table 1](#dvr)).\n\n\n`NDK_DEBUG=0`\n:\n Force a release build (see [table 1](#dvr)).\n\n\n`NDK_HOST_32BIT=1`\n:\n Always use the toolchain in 32-bit mode.\n\n\n`NDK_APPLICATION_MK=\u003cfile\u003e`\n:\n Build, using a specific `Application.mk` file pointed to by the\n `NDK_APPLICATION_MK` variable.\n\n\n`-C \u003cproject\u003e`\n:\n Build the native code for the project path located at\n `\u003cproject\u003e`. Useful if you don't want to `cd`\n to it in your terminal.\n\n### Debuggable versus release builds\n\nUse the `NDK_DEBUG` option and, in certain cases,\n`AndroidManifest.xml` to specify debug or release build,\noptimization-related behavior, and inclusion of symbols. Table 1 shows the\nresults of each possible combination of settings.\n\n**Table 1.** Results of `NDK_DEBUG` (command line) and\n`android:debuggable` (manifest) combinations.\n\n| Manifest Setting | NDK_DEBUG=0 | NDK_DEBUG=1 | NDK_DEBUG not specified |\n|----------------------------|------------------------------|----------------------------------|-----------------------------------|\n| android:debuggable=\"true\" | Debug; Symbols; Optimized\\*1 | Debug; Symbols; Not optimized\\*2 | (same as NDK_DEBUG=1) |\n| android:debuggable=\"false\" | Release; Symbols; Optimized | Release; Symbols; Not optimized | Release; No symbols; Optimized\\*3 |\n\n\\*1: Useful for profiling. \n\\*2: Default for running [`ndk-gdb`](/ndk/guides/ndk-gdb). \n\\*3: Default mode. \n\n**Note:** \\`NDK_DEBUG=0\\` is the equivalent of\n\\`APP_OPTIM=release\\`, and compiles with \\`-O2\\`. \\`NDK_DEBUG=1\\` is the equivalent of\n\\`APP_OPTIM=debug\\` in \\`Application.mk\\`, and compiles with \\`-O0\\`.\nFor more information about \\`APP_OPTIM\\`, see\n[Application.mk](/ndk/guides/application_mk).\n\nThe syntax on the command line is, for example: \n\n```\n$ ndk-build NDK_DEBUG=1\n```\n\nRequirements\n------------\n\nYou need GNU Make 4 to use ndk-build or the NDK in general. The NDK includes its\nown copy of GNU Make and will use that unless you've set the `$GNUMAKE`\nenvironment variable to point to an unsuitable make.\n\nJSON compilation databases\n--------------------------\n\nIn NDK r18 and newer, ndk-build can generate a\n[JSON compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html).\n\nYou can either use `ndk-build compile_commands.json` to generate the database\nwithout building your code, or `ndk-build GEN_COMPILE_COMMANDS_DB=true` if you\nwant to build and generate the database as a side-effect."]]