README.md 4.11 KB
Newer Older
Dan Albert's avatar
Dan Albert committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
Android Native Development Kit (NDK)
====================================

The NDK allows Android application developers to include
native code in their Android application packages, compiled as JNI shared
libraries.

See [the Getting Started Guide](docs/Getting_Started/html/index.html) for an
introduction.

See [the changelist](docs/Change_Log.html) for a list of changes since the
previous release.

Finally, discussions related to the Android NDK happen on the
[android-ndk](http://groups.google.com/group/android-ndk) Google Group.

Building the NDK
================

**Note:** This document is for developers _of_ the NDK, not developers
that use the NDK.

Both Linux and Windows host binaries are built on Linux machines. Windows host
Elliott Hughes's avatar
Elliott Hughes committed
24
binaries are built via MinGW cross compiler. Systems without a working MinGW
Dan Albert's avatar
Dan Albert committed
25 26 27
compiler can use `build/tools/build-mingw64-toolchain.sh` to generate their own
and be added to the `PATH` for build scripts to discover.

28
Building binaries for Mac OS X requires at least 10.8.
Dan Albert's avatar
Dan Albert committed
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

Target headers and binaries are built on Linux.

Components
----------

The NDK consists of three parts: host binaries, target prebuilts, and others
(build system, docs, samples, tests).

### Host Binaries

* `toolchains/` contains GCC, Clang, and Renderscript toolchains.
    * `$TOOLCHAIN/config.mk` contains ARCH and ABIS this toolchain can handle.
    * `$TOOLCHAIN/setup.mk` contains toolchain-specific default CFLAGS/LDFLAGS
      when this toolchain is used.
Elliott Hughes's avatar
Elliott Hughes committed
44
* `prebuilt/$HOST_ARCH/` contains various tools to make the build system hermetic.
Dan Albert's avatar
Dan Albert committed
45
    * make, awk, sed, python, yasm, and for Windows: cmp.exe and echo.exe
Dan Albert's avatar
Dan Albert committed
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
* `ndk-depends` and `ndk-stack` should probably go in `prebuilt/` to avoid
  collisions between host variants.


### Target Headers and Binaries

* `platforms/android-N/arch-$ARCH_NAME/` contains headers and libraries for each
  API level.
    * The build system sets `--sysroot` to one of these directories based on
      user-specified `APP_ABI` and `APP_PLATFORM`.
* `sources/cxx-stl/$STL/$ABI/` contains the headers and libraries for the various
  C++ STLs.
* `prebuilt/android-$ARCH/gdbserver/` contains gdbserver.

### Others

* `build/` contains the ndk-build system and scripts to rebuild NDK.
* `docs/`
* `samples/`
* `sources/` contains modules useful in samples and apps via
  `$(call import-module, $MODULE)`
* `tests/`

Prerequisites
-------------

72 73
* [AOSP NDK Repository](http://source.android.com/source/downloading.html)
    * Check out the branch `master-ndk`
Dan Albert's avatar
Dan Albert committed
74 75

        ```bash
76 77
        repo init -u https://android.googlesource.com/platform/manifest \
            -b master-ndk
78 79 80 81 82

        # Googlers, use
        repo init -u \
            persistent-https://android.git.corp.google.com/platform/manifest \
            -b master-ndk
Dan Albert's avatar
Dan Albert committed
83 84
        ```

85 86 87
    * The only difference between the NDK branch and master is that the NDK
      repository already has the toolchain repository checked out and patched.

Dan Albert's avatar
Dan Albert committed
88 89 90 91 92 93 94 95 96 97 98 99 100 101
* Additional Linux Dependencies (available from apt):
    * texinfo
    * gcc-mingw32
    * wine
    * bison
    * flex
    * dmake
    * libtool
    * pbzip2
* Mac OS X also requires Xcode.

Host/Target prebuilts
---------------------

102
### For Linux or Darwin:
Dan Albert's avatar
Dan Albert committed
103 104

```bash
105
$ python checkbuild.py --no-package
Dan Albert's avatar
Dan Albert committed
106 107
```

108
### For Windows, from Linux:
Dan Albert's avatar
Dan Albert committed
109 110

```bash
111
$ python checkbuild.py --system windows
Dan Albert's avatar
Dan Albert committed
112 113 114 115 116
```

Packaging
---------

117 118 119
The simplest way to package an NDK on Linux is to just omit the `--no-package`
flag when running `checkbuild.py`. This will take a little longer though, so it
may not be desired for day to day development.
Dan Albert's avatar
Dan Albert committed
120

121 122 123
To package the NDK for Windows or Darwin (or if more control over the packaging
process is needed), invoke `build/tools/package-release.sh` directly. This
process will be improved in a future commit.
Dan Albert's avatar
Dan Albert committed
124 125 126 127 128 129 130 131 132 133

Best Practices for Incremental Builds
-------------------------------------

* Do not run `build/tools/dev-cleanup.sh` which erases all prebuilts.
* Remove the individual prebuilt directory if new build deletes files. This is
  rare.
* Package NDK from prebuilt tarballs in `$PREBUILT_PATH`. It runs
  `build/tools/build-docs.sh` which produces no tarball in `$PREBUILT_PATH`.
* Unpack and compare against the previous package.