method 1.
1.google上直接下载NDK源码解压即可,目前版本为 android-ndk-r9d
配置$NDK_HOME 和 $PATH
export NDK_HOME=/XXX/android-ndk-r9d
export PATH=$NDK_HOME:$PATH
2.提取toolchain
参考:docs/STANDALONE-TOOLCHAIN.html
a.查看目标 指令集 arm or x86 or mips
b.配置gcc编译时所用头文件和根文件的目录 $SYSROOT
SYSROOT=$NDK_HOME/platforms/android-18/arch-arm
export SYSROOT
c.调用NDK编译器
$NDK_HOME/build/tools/make-standalone-toolchain.sh --platform=android-18 --install-dir=/tmp/my-android-toolchain
[ --arch=x86 ] 默认为arm
d.设置 $PATH和$CC(相当与平时的gcc)
export PATH=/tmp/my-android-toolchain/bin:$PATH
export CC=arm-linux-androideabi-gcc # or export CC=clang
export CXX=arm-linux-androideabi-g++ # or export CXX=clang++
3.即可用$CC -o hello hello.c
4.上传hello至emulator
可传至/data/下:adb push hello /data/
若下载可用:adb pull XX XX
也可上传至sdcard,但此时对sdcard只有读权限,需先激活模拟器的sdcard,具体方法:SDK目录下:mksdcard -l sdcard 100M /XX/sdcard.img 然后在运行模拟器时加上-sdcard sdcard.img即可加载自己的sdcard;然后可用eclipse的DDMS中的pull和push按键进行上传下载
5.打开模拟器:adb shell
6.运行hello:/data/hello
method 2.
export NDK_HOME=/XXX/android-ndk-r9d
export PATH=$NDK_HOME:$PATH
open eclipse
import /$NDK_HOME/samples/hello-jni
HelloJni(right click)----properties
builders----new----Program:
//////Main//////
Name:NDK_Builder
Location:/bin/bash
Working directory:/bin
Arguments:--login -c "cd /XX/android-ndk-r9d/samples/hello-jni && $NDK_HOME/ndk-build"
//////Refresh//////
refresh resources upon completion
//////Build Options//////
click the last three options----Specify resources----Hello Jni
Ok
up NDK_Builder to the first place
Ubuntu下 Android NDK安装,布布扣,bubuko.com