如何使用Android.mk编译简单的本机代码? [英] How do I compile simple native code using Android.mk?
问题描述
尤其是我正在尝试编译chainDD的su二进制文件.我尝试使用ndk-build
,但是似乎我需要设置NDK_PROJECT_PATH
,但是文档中没有对此进行设置.
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.
推荐答案
首先,请确保您拥有NDK:
First, make sure you have the NDK:
http://developer.android.com/tools/sdk/ndk/index.html
这是为手机编译C二进制文件的最简单方法:
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
通常$ NDK(可能有所不同)=
Usually $NDK(may be different) =
Linux:
/home/<user>
/android-ndk
/home/<user>
/android-ndk
Mac OS X:
/Users/<user>
/android-ndk
/Users/<user>
/android-ndk
两者: $ HOME/android-ndk
Both: $HOME/android-ndk
在终端机中:
# 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!
此致
这篇关于如何使用Android.mk编译简单的本机代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!