创建helloworld程序
#include <stdio.h> int main(){ printf("helloworld\n"); }
使用工具链里的gcc工具来编译该helloworld可执行文件(需要指定sysroot)
/root/android-ndk-r10/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gc> c helloworld.c -o helloworld --sysroot=/root/android-ndk-r10/platforms/android-L/arch-arm
push该helloworld到一部安卓机器上,由于android的一些权限机制,位于sdcard下的目录默认都是不可运行的,也就是说,如果adb push到这两个目录下还是会出现没有权限运行(我试过在smatisan t1上,即使我有root权限,也会修改文件权限不成功),所以我们的做法是放到/data/local/tmp目录下
adb push helloworld /data/local/tmp
然后
chmod 777 helloworld//(不需要root也可以执行)
之后就可以成功运行该helloworld程序了。
./helloworld
使用ndk工具链创建在安卓机器上的可执行文件
最新推荐文章于 2021-05-27 18:28:26 发布