ndk-build スクリプト
コレクションでコンテンツを整理
必要に応じて、コンテンツの保存と分類を行います。
ndk-build
スクリプトは、NDK の Make ベースのビルドシステムを使用するプロジェクトをビルドします。ndk-build
が使用する Android.mk と Application.mk の構成については、それぞれのリンク先に詳しいドキュメントがあります。
内部動作
ndk-build
スクリプトを実行することは、次のコマンドを実行することと同等です。
$GNUMAKE -f <ndk>/build/core/build-local.mk
<parameters>
$GNUMAKE
は GNU Make 3.81 以降を指し、<ndk>
は NDK インストール ディレクトリを指します。この情報を使用して、他のシェル スクリプトまたは独自の Makefile から ndk-build を呼び出すことができます。
コマンドラインから呼び出す
ndk-build
スクリプトは NDK インストール ディレクトリの最上位にあります。このスクリプトをコマンドラインから実行するには、アプリ プロジェクト ディレクトリ内、またはそのディレクトリの下でスクリプトを呼び出します。次に例を示します。
$ cd <project>
$ <ndk>/ndk-build
この例では、<project>
はプロジェクトのルート ディレクトリを指し、<ndk>
は NDK をインストールしたディレクトリを指します。
オプション
ndk-build に対するパラメータはすべて、実質的に NDK ビルド スクリプトを実行する GNU make
コマンドに直接渡されます。ndk-build
とオプションを ndk-build <option>
の形式で組み合わせます。次に例を示します。
$ ndk-build clean
使用できるオプションは次のとおりです。
-
clean
- 以前に生成したバイナリをすべて削除します。
注: Mac OS X では、並列実行数が多い状況で ndk-build clean
を実行すると、次のメッセージを含むビルドエラーが発生する可能性があります。
rm: fts_read: No such file or directory
この問題を回避するには、-jN
修飾子の使用を避けるか、2 のような小さな値を N
に指定します。
-
V=1
- ビルドを開始し、ビルドコマンドを表示します。
-
-B
- 完全な再ビルドを強制的に実施します。
-
-B V=1
- 完全な再ビルドを強制的に実施し、ビルドコマンドを表示します。
-
NDK_LOG=1
- NDK 内部ログメッセージを表示します(NDK 自体のデバッグに使用します)。
-
NDK_DEBUG=1
- デバッグ可能ビルドを強制的に実施します(表 1 を参照)。
-
NDK_DEBUG=0
- リリースビルドを強制的に実施します(表 1 を参照)。
-
NDK_HOST_32BIT=1
- 常に 32 ビットモードのツールチェーンを使用します。
-
NDK_APPLICATION_MK=<file>
NDK_APPLICATION_MK
変数がポイントする特定の 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」は Application.mk の「APP_OPTIM=release」と同等であり、「-O2」でコンパイルされます。「NDK_DEBUG=1」は「APP_OPTIM=debug」と同等であり、「-O0」でコンパイルされます。「APP_OPTIM」について詳しくは、Application.mk をご覧ください。
コマンドラインの構文の例は次のとおりです。
$ ndk-build NDK_DEBUG=1
要件
一般的に、ndk-build または NDK を使用するには、GNU Make 4 が必要です。NDK は GNU Make の独自のコピーを含んでおり、$GNUMAKE
環境変数が不適切な Make をポイントするように設定されていない限り、そのコピーを使用します。
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."]]