1 <html><body><pre>'ndk-build' Overview 2 3 I. Usage: 4 --------- 5 6 The Android NDK r4 introduced a new tiny shell script, named 'ndk-build', 7 to simplify building machine code. 8 9 The script is located at the top-level directory of the NDK, and shall 10 be invoked from the command-line when in your application project 11 directory, or any of its sub-directories. For example: 12 13 cd $PROJECT 14 $NDK/ndk-build 15 16 Where $NDK points to your NDK installation path. You can also create an 17 alias or add $NDK to your PATH to avoid typing it every time. 18 19 20 II. Options: 21 ------------ 22 23 All parameters to 'ndk-build' are passed directly to the underlying GNU Make 24 command that runs the NDK build scripts. Notable uses include: 25 26 ndk-build --> rebuild required machine code. 27 ndk-build clean --> clean all generated binaries. 28 29 ndk-build NDK_DEBUG=1 --> generate debuggable native code. 30 31 ndk-build V=1 --> launch build, displaying build commands. 32 33 ndk-build -B --> force a complete rebuild. 34 35 ndk-build -B V=1 --> force a complete rebuild and display build 36 commands. 37 38 ndk-build NDK_LOG=1 --> display internal NDK log messages 39 (used for debugging the NDK itself). 40 41 ndk-build NDK_DEBUG=1 --> force a debuggable build (see below) 42 ndk-build NDK_DEBUG=0 --> force a release build (see below) 43 44 ndk-build NDK_HOST_32BIT=1 --> Always use toolchain in 32-bit (see below) 45 46 ndk-build NDK_APPLICATION_MK=<file> 47 --> rebuild, using a specific Application.mk pointed to by 48 the NDK_APPLICATION_MK command-line variable. 49 50 ndk-build -C <project> --> build the native code for the project 51 path located at <project>. Useful if you 52 don't want to 'cd' to it in your terminal. 53 54 55 III. Debuggable versus Release builds: 56 -------------------------------------- 57 58 In NDK r5, ndk-build has been modified to make it easier to switch between 59 release and debug builds. This is done by using the NDK_DEBUG variable. 60 For example: 61 62 $NDK/ndk-build NDK_DEBUG=1 => forces the generation of debug binaries 63 $NDK/ndk-build NDK_DEBUG=0 => forces the generation of release binaries 64 65 If you don't specify NDK_DEBUG, ndk-build will keep its default behaviour, 66 which is to inspect the AndroidManifest.xml, if any, and see if its 67 <application> element has android:debuggable="true". 68 69 IMPORTANT: If you use the build tools of SDK r8 (or higher), you 70 won't need to touch your AndroidManifest.xml file at all! 71 72 That's because if you build a debug package (e.g. with 73 "ant debug" or the corresponding option of the ADT plugin), 74 the tool will automatically pick the native debug files 75 generated with NDK_DEBUG=1. 76 77 Also, as a convenience, the release and debug object files generated by the 78 NDK are now stored in different directories (e.g. obj/local/<abi>/objs and 79 obj/local/<abi>/objs-debug). This avoids having to recompile all your sources 80 when you switch between these two modes (even when you only modified one or 81 two source files). 82 83 84 IV. 64-bit and 32-bit toolchains: 85 --------------------------------- 86 87 Some toolchains come with both 64-bit and 32-bit versions. For example, 88 directories $NDK/toolchain/<name>/prebuilt and $NDK/prebuilt may contains both 89 "linux-x86" and "linux-x86_64" folders for Linux tools in 32-bit and 64-bit modes, 90 respectively. The ndk-build script automatically chooses a 64-bit version of the 91 toolchain if the host OS supports it. You can force the use of a 32-bit toolchain by 92 using NDK_HOST_32BIT=1 either in your envorinment or on the ndk-build command-line. 93 94 Note that 64-bit tools utilize host resources better (faster, handle larger 95 programs, etc) and they should function identically to their 32-bit counterparts. 96 Ie. 64-bit toolchains still generate 32-bit binaries for Android. 97 98 99 V. Requirements: 100 ---------------- 101 102 You need GNU Make 3.81 or later to use 'ndk-build' or the NDK in general. 103 The build scripts will detect that you're using a non-compliant Make tool 104 and will complain with an error message. 105 106 If you have GNU Make 3.81 installed, but that it is not launched by the 107 default 'make' command, define GNUMAKE in your environment to point to it 108 before launching 'ndk-build'. For example: 109 110 GNUMAKE=/usr/local/bin/gmake ndk-build 111 112 Or to make the change more permanent: 113 114 export GNUMAKE=/usr/local/bin/gmake 115 ndk-build 116 117 Adapt to your shell and GNU Make 3.81 installation location. 118 119 You may override other host prebuilt tools in $NDK/prebuilt/<OS>/bin 120 with the following environment variables 121 122 NDK_HOST_AWK=<path-to-awk> 123 124 NDK_HOST_ECHO=<path-to-echo> 125 126 NDK_HOST_CMP=<path-to-cmp> 127 128 129 VI. Internals: 130 -------------- 131 132 'ndk-build' itself is a tiny wrapper around GNU Make, its purpose is simply 133 to invoke the right NDK build script, it is equivalent to; 134 135 $GNUMAKE -f $NDK/build/core/build-local.mk [parameters] 136 137 Where '$GNUMAKE' points to GNU Make 3.81 or later, and $NDK points to your 138 NDK installation directory. 139 140 Use this knowledge if you want to invoke the NDK build script from other 141 shell scripts (or even your own Makefiles). 142 </pre></body></html> 143