创建一个Native c++ 工程:
在cpp 目录下添加编写自己的.c
#include <stdio.h>
int main() {
printf("c executable project\n");
printf("hello world ! run form C\n");
return 1;
}
在CmakeLists.txt 中 增加 add_executable(hello hello.c) 用于编译可执行文件:
这样就OK了, build 完后, 在CProject\app\build\intermediates\cmake\debug\obj\arm64-v8a 可以找到hello的可执行文件
通过adb push 到手机里, 修改权限后可以运行:
adb push hello /data/local/tmp/
adb shell
cd /data/local/tmp
chmod 777 hello
./hello
另外你也可以用linux 下, android 源码自带的gcc来自己编译你的hello.c 生产可执行文件:
arm-linux-gnueabihf-gcc 在android源码下面目录
prebuilts/gcc/linux-x86/arm/arm-linux-androideabi-4.9/bin/
你可以cd到这个目录用下面命令编译:
./arm-linux-gnueabihf-gcc hello.c -o hello -static