环境:ubuntu 12.04 x64
1. 下载ndk
- wget
- tar xfj android-ndk-r8b-linux-x86.tar.bz2
2. 设置环境变量
- export PATH=/home/android/android-ndk-r8b:$PATH
3. helloworld project结构
- mkdir hello
- cd hello
- mkdir jni
- cd jni
vi hello.c:
- // hello.c
- #include <stdio.h>
- int main(int argc, char *argv[])
- {
- printf("hello\n");
- return 0;
- }
vi Android.mk:
- // Android.mk
- LOCAL_PATH:= $(call my-dir)
- include $(CLEAR_VARS)
- LOCAL_SRC_FILES:= hello.c
- LOCAL_MODULE:= hello
- LOCAL_FORCE_STATIC_EXECUTABLE := true
- include $(BUILD_EXECUTABLE)
4. 编译(生成可执行文件在../libs/armeabi/)
5. 传到手机上运行
- cd ../libs/armeabi
- adb push hello /sdcard/hello
- adb shell
- su
- cd /sdcard
- cp hello /data
- chmod 755 hello
- ./hello
在sdcard下面执行时,会出现permission denied,移动到/data目录下,添加执行权限后,可以正常执行。
参考:
http://leave001.blog.163.com/blog/static/16269129320111128113217384/
阅读(7312) | 评论(0) | 转发(2) |