天天看点

Build your own NDK from the Android source treePrerequisitesBuild the NDKUse the new NDK sysroot

Let’s say you want to port a Linux tool to Android. You got the latest NDK and you tried building the Linux tool you want to port. You tool does not build because it depends on the latest bionic changes that did not make it into the latest NDK release. What can you do? Build your own NDK from Google’s source tree that will contain the latest bionic changes.

Prerequisites

If you haven’t done this already, you need to download the latest Google tree and compile it.

Build the NDK

You need to run the NDK script that builds sysroot. sysroot is the directory that will contain the libraries and header files for your target. You need to specify the ABI you want for the target.

For x86 you need to run:

$ ./ndk/build/tools/build-ndk-sysroot.sh --abi=x86

and for arm:

$ ./ndk/build/tools/build-ndk-sysroot.sh --abi=arm

Use the new NDK sysroot

If you want to cross compile any C application, you’ll need to use the new sysroot for NDK.

For x86:

$ export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-x86

For arm:

$ export NDK_SYSROOT=${ANDROID_BUILD_TOP}/ndk/build/platforms/android-3/arch-arm

For details on how to cross compile a C application see Cross-compiling a C application using the Android NDK.

https://yaapb.wordpress.com/2012/09/27/build-your-own-ndk-from-the-google-source-tree/