一。建立一个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
本文介绍了如何使用Android NDK创建并编译一个简单的应用程序。包括设置必要的文件如 Android.mk 和 hello.c,编译过程及如何将应用部署到模拟器上。
770

被折叠的 条评论
为什么被折叠?



