The latest version of this document is available at https://android.googlesource.com/platform/ndk/+/master/docs/GeneratingSysroots.md.
Note: This document covers the old method of getting platform APIs into the NDK. The new process is covered by Platform APIs. APIs that were created using the old process are still shipped (until r16), but no new APIs are added this way.
platforms/ subtree of an NDK package contains sysroots for each architecture and API level. The contents of these sysroots are generated as part of the NDK build.
The contents of the sysroots are defined by
development/ndk/platforms. Note that this is from the top level of the Android tree, not within the
The layout of this tree is as follows:
These trees are a very reduced form of a sysroot. Not every header or library will be in every platform version. Instead, gen-platforms.sh will build the full sysroot from what is defined here. This is done to ease maintenance of the headers and libraries. If, for example,
string.h remained the same between Gingerbread and KitKat, but was updated in Lollipop, there need only be a copy of
string.h in android-9 and android-21, not in every intermediate release.
When an NDK binary links against a platform library, rather than shipping a copy of the library with the binary, it loads the library from the system itself (in the case of an app, many of the libraries will already be loaded into the address space by the zygote). As such, the shared libraries in the NDK do not need to be valid aside from the symbols they expose. This simplifies things, because all we need to generate the shared libraries for a given architecture and platform version is a list of functions and variables.
android-$VERSION/arch-$ARCH/symbols/*.txt files contain these library definitions. Each file is named either
$LIBNAME.variables.txt. For each such file, gen-platforms.sh will create a stub shared library for that library with the functions and variables defined in those lists.
For some platform versions (currently only android-23), there is also a
$LIBNAME.versions.txt. This is a linker version script that will be used to apply symbol versions when generating the stub shared library.
Examples of each of these three file types can be found in development/ndk/platforms/android-23/arch-arm64/symbols.
Follow Platform APIs.