اسکریپت ndk-build
با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
اسکریپت ndk-build
پروژه هایی را می سازد که از سیستم ساخت مبتنی بر Make-based 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 از اسکریپتهای پوسته دیگر یا حتی فایلهای make خودتان استفاده کنید.
از خط فرمان فراخوانی کنید
اسکریپت 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
برای جلوگیری از این مشکل، از اصلاح کننده -j N
استفاده نکنید یا مقدار کوچکتری را برای N
انتخاب نکنید، مانند 2.
-
V=1
- build را اجرا کنید و دستورات ساخت را نمایش دهید.
-
-B
- مجبور به بازسازی کامل
-
-BV=1
- مجبور به بازسازی کامل، و نمایش دستورات ساخت.
-
NDK_LOG=1
- نمایش پیام های گزارش داخلی NDK (برای اشکال زدایی خود NDK استفاده می شود).
-
NDK_DEBUG=1
- یک ساخت قابل اشکال زدایی را اجباری کنید ( جدول 1 را ببینید).
-
NDK_DEBUG=0
- اجباری ساختن رهاسازی ( جدول 1 را ببینید).
-
NDK_HOST_32BIT=1
- همیشه از زنجیره ابزار در حالت 32 بیتی استفاده کنید.
-
NDK_APPLICATION_MK=<file>
- ساخت، با استفاده از یک فایل
Application.mk
خاص که توسط متغیر NDK_APPLICATION_MK
به آن اشاره شده است. -
-C <project>
- کد بومی مسیر پروژه واقع در
<project>
را بسازید. اگر نمی خواهید در ترمینال خود به آن cd
مفید است.
اشکال زدایی در مقابل نسخه های انتشار
از گزینه NDK_DEBUG
و در موارد خاص AndroidManifest.xml
برای تعیین اشکالزدایی یا انتشار ساخت، رفتار مرتبط با بهینهسازی و گنجاندن نمادها استفاده کنید. جدول 1 نتایج هر ترکیب ممکن از تنظیمات را نشان می دهد.
جدول 1. نتایج ترکیبات NDK_DEBUG
(خط فرمان) و android:debuggable
(مانیفست).
تنظیم مانیفست | NDK_DEBUG=0 | NDK_DEBUG=1 | NDK_DEBUG مشخص نشده است |
---|
android:debuggable="true" | اشکال زدایی؛ نمادها؛ بهینه شده*1 | اشکال زدایی؛ نمادها؛ بهینه نشده*2 | (همانند NDK_DEBUG=1) |
android:debuggable="false" | انتشار؛ نمادها؛ بهینه شده است | انتشار؛ نمادها؛ بهینه نشده است | انتشار؛ بدون نماد؛ بهینه شده*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
الزامات
برای استفاده از ndk-build یا به طور کلی NDK به GNU Make 4 نیاز دارید. NDK شامل کپی خودش از GNU Make است و از آن استفاده خواهد کرد مگر اینکه متغیر محیطی $GNUMAKE
طوری تنظیم کرده باشید که به یک ساخت نامناسب اشاره کند.
پایگاه داده های جمع آوری JSON
در NDK r18 و جدیدتر، ndk-build می تواند یک پایگاه داده کامپایل JSON ایجاد کند.
می توانید از ndk-build compile_commands.json
برای تولید پایگاه داده بدون ساخت کد خود استفاده کنید، یا اگر می خواهید پایگاه داده را به عنوان یک اثر جانبی بسازید و تولید کنید ndk-build GEN_COMPILE_COMMANDS_DB=true
استفاده کنید.
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-07-29 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","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-29 بهوقت ساعت هماهنگ جهانی."],[],[],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."]]