引用:http://blog.sina.com.cn/s/blog_4a0a39c30100auh9.htmlhtml
Android是基于Linux的操做系统,处理器是ARM的,因此要在Linux或Windows等x86系统上编译Android能运行的程序,你须要一个交叉编译器。linux
在Linux下面,你能够自已编译一个交叉编译环境,但Windows下面,就比较复杂(也能够在cygwin中编译一个),但你能够选择下载一个现成的交叉编译环境:android
http://www.codesourcery.com/gnu_toolchains/arm/download.htmlshell
安装好了以后,将 CodeSourcery编译器的bin目录 (个人是D:\Program Files\CodeSourcery\Sourcery G++ Lite\bin) 加入你的PATH环境变量中,就能够开始你的Android Native C开发之旅了,写好一个简单的C程序:code
#include <stdlib.h>htm
int main(int argc, char** argv) {
printf("hello android!\nI'm %s!\nI like android very much!!!\n", "Martin Foo");
return 0;
}blog
另存成hello.c,进入命令行模式,确保交叉编译器的bin目录,及Android SDK的tools目录在你的系统环境变量的path里面,用以下命令编译:开发
arm-none-linux-gnueabi-gcc -static hello.c -o hello
注意,必定要加上static参数,不然编译好的可能会在Android上不能运行。
启动Android模拟器,用以下命令将文件push到Android模拟器上:
adb shell mkdir /dev/sample
adb push hello /dev/sample/hello
adb shell chmod 777 /dev/sample/hello
先建立 /dev/sample目录,再将编译好的hello上传上去,最后将hello改为可执行的。
再进入命令行模式,进入Android的shell环境:
adb shell