一。建立一个Android NDK工程: 很简单,就是模仿NDK下面的JNI例子需要俩个文件:ANDORID.MK和hello.c
Android.mk内容:
LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS)
LOCAL_MODULE :=hello
LOCAL_SRC_FILES := hello.c
include $(BUILD_EXECUTABLE)
hello.c的内容:
#include <stdio.h>
int main() {
printf("fuck\n");
return 0;
}
二。编译和运行: 进入工程目录,然后进行编译:
@ubuntu:~/hello$~/android/android-ndk-r5/ndk-build Compile thumb : hello <= hello-jni.cExecutable : hello Install : hello => libs/armeabi/hello
@ubuntu:~/hello$ls jni libs obj
@ubuntu:~/hello$ cd /home/lex/android/
@ubuntu:~/android$cd android
@ubuntu:~/android/android$ . build/envsetup.sh includingvendor/aosp/vendorsetup.sh
@ubuntu:~/android/android$ lunch
然后push到模拟器里面就可以运行了:
@ubuntu:~/android/build/linux-x86/bin$./adb push ~/hello/libs/armeabi/hello /data/local/ 32 KB/s (2168 bytes in0.065s)
@ubuntu:~/android/build/linux-x86/bin$ ./adb shell # cd data/local #ls hello tmp # ./hello fuck