Android技术16:编写Android中直接可运行的二进制文件 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【www.unjs.com - 电脑资料】

   

    我们都知道Android中所有应用程序都运行在Android的Dalvik虚拟机上,一般程序不直接与操作系统打交道,即便调用底层的方法也通过JNI技术,

Android技术16:编写Android中直接可运行的二进制文件

。不过我们可以直接使用C语言编写二进制文件,直接在底层运行。下面演示其步骤。

    1.安装下载编译器和链接器软件.Sourcery G++ Lite Edition for ARM.

    arm-none-linux-gnueabi-gcc.exe是编译命令

    bin/arm-none-linux-gnueabi-ld.exe是链接命令

    2.编写C代码

    为了演示方便编写最简单的代码,输出hello,world,例如:我在d:/temp目录写建立hello.c文件

    #include

    int main(){

    printf("helloworld\n");

    return 0;

    }

    3.编译hello.c文件

    cmd---d:/---cd temp进入temp目录下arm-none-linux-gnueabi-gcc hello.c -static -o hello,在目录中生成hello二进制文件

    4.将hello文件push到手机

    启动模拟器---adb push hello /data/data/hello

    5.修改属性

    adb shell

    cd /data/data/

    chmod 777 hello

    将hello修改为可执行文件

    6.执行文件

    ./hello

    7.显示

    helloworld

   

最新文章