Home | History | Annotate | Download | only in docs
      1 <html><body><pre>Android NDK How-To:
      2 ===================
      3 
      4 A collection of tips and tricks for NDK users
      5 
      6 
      7 How to force the display of build commands:
      8 -------------------------------------------
      9 
     10 Do "ndk-build V=1" and actual build commands will be
     11 displayed. This can be used to verify that things are compiled
     12 as you expect them to, and check for bugs in the NDK build system.
     13 
     14 (The V=1 trick comes from the Linux kernel build system)
     15 
     16 
     17 How to force a rebuild of all your sources:
     18 -------------------------------------------
     19 
     20 Use GNU Make's "-B" option, as in:
     21 
     22    ndk-build -B
     23 
     24 
     25 How to store your native sources in a location other than $PROJECT/jni:
     26 -----------------------------------------------------------------------
     27 
     28 First, you can simply tell your $PROJECT/jni/Android.mk to include
     29 another Android.mk that are located in different places.
     30 
     31 Alternatively, you can define APP_BUILD_SCRIPT in your Application.mk
     32 to point to an alternative Android.mk file.
     33 
     34 
     35 How to build a project's native files without cd-ing to it:
     36 -----------------------------------------------------------
     37 
     38 Sometimes, you may need to rebuild a project's native file without
     39 being able to cd to its top-level path from the command-line. This
     40 is do-able by using the GNU-Make '-C &lt;path&gt;' option, as in:
     41 
     42     ndk-build -C &lt;project-path&gt;
     43 
     44 
     45 How to store your Application.mk in a location other than $PROJECT/jni:
     46 -----------------------------------------------------------------------
     47 
     48 Starting with NDK r4, you can simply place the file under $PROJECT/jni/
     49 and launch the 'ndk-build' script from your project tree.
     50 
     51 If you want to use 'ndk-build' but place the file to a different location,
     52 use a GNU Make variable override as:
     53 
     54     ndk-build NDK_APPLICATION_MK=/path/to/your/Application.mk
     55 
     56 If you're using the legacy $NDK/apps/&lt;name&gt; build method, you can create
     57 a symbolic link to your final Application.mk there. For example, imagine
     58 that you wrote:
     59 
     60   $PROJECT/foo/Application.mk
     61 
     62 You can create a symlink like with a command like:
     63 
     64   ln -s $PROJECT/foo  $NDK/apps/&lt;name&gt;
     65 
     66 This will make $NDK/apps/&lt;name&gt;/Application.mk point directly to
     67 $PROJECT/jni/Application.mk
     68 
     69 Note that generated files will still go under $NDK/out/apps/&lt;name&gt; though.
     70 
     71 Windows users: The NDK is only supported on Cygwin, which implements
     72 symbolic links through the "ln -s" command, as in:
     73 
     74     ln -s  &lt;target&gt;  &lt;link&gt;
     75 
     76 
     77 How to properly add include directories to your module declaration:
     78 -------------------------------------------------------------------
     79 
     80 If you define several modules, it is common to need to include one
     81 module's header while compiling another one. For example, consider
     82 the following example:
     83 
     84   $PROJECT/jni/foo/
     85     Android.mk
     86     foo.h
     87     foo.c
     88 
     89   $PROJECT/jni/bar/
     90     Android.mk
     91     bar.c
     92 
     93 Where the 'bar.c' uses '#include &lt;foo.h&gt;'. You will need to add the
     94 path to the 'foo' module in jni/bar/Android.mk to build it properly.
     95 
     96 One is tempted to use the following:
     97 
     98   LOCAL_C_INCLUDES := ../foo
     99 
    100 However this will not work because all compilation happens from the
    101 directory where 'ndk-build' is invoked, and include files must be
    102 relative to it.
    103 
    104 The correct line is instead:
    105 
    106   LOCAL_C_INCLUDES := $(LOCAL_PATH)/../foo
    107 
    108 Which uses a path relative to $(LOCAL_PATH), in the case where you would
    109 need to move 'foo' and 'bar' to a deeper level in the 'sources' hierarchy.
    110 
    111 In case you absolutely need it, you can also use NDK_APP_PROJECT_PATH to
    112 point to your project directory:
    113 
    114   LOCAL_C_INCLUDES := $(NDK_APP_PROJECT_PATH)/jni/foo
    115 
    116 However, we don't recommend using this, paths relative to $(LOCAL_PATH)
    117 being better.
    118 
    119 </pre></body></html>