开发者

How do I compile simple native code using Android.mk?

In particular I am trying to compile chainDD's su binary. I tried开发者_开发问答 to use ndk-build but it seems I need to set NDK_PROJECT_PATH but what this should be set to is not described in the documentation.


First, make sure you have the NDK:

http://developer.android.com/tools/sdk/ndk/index.html

Here is the easiest way to compile a C binary for your phone:

http://developer.android.com/tools/sdk/ndk/index.html

http://www.kandroid.org/ndk/docs/STANDALONE-TOOLCHAIN.html

Usually $NDK(may be different) =

Linux:

/home/<user>/android-ndk

Mac OS X:

/Users/<user>/android-ndk

Both: $HOME/android-ndk

In Terminal:

# create tool-chain - one line
$NDK/build/tools/make-standalone-toolchain.sh --platform=android-3 --install-dir=/tmp/my-android-toolchain

# add to terminal PATH variable
export PATH=/tmp/my-android-toolchain/bin:$PATH

# make alias CC be the new gcc binary
export CC=arm-linux-androideabi-gcc

# compile your C code(I tried hello world)
$CC -o foo.o -c foo.c

# push binary to phone
adb push foo.o /data/local/tmp

# execute binary
adb /data/local/tmp/foo.o

Please let me know if I can help!

Regards,


You need establish your project folder like this:

project_root

|__ jni/ (include Android.mk and your C/C++ code)

|__ other_directory

The jni directory can't change name. and run ndk-build in project_root directory.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜