以前我时常在想,怎么能在AndroID系统中用C语言来编写应用程序呢?AndroID系统上的应用程序不都是Java应用程序吗?其实是可以的,读者不妨用adb shell命令连上AndroID模拟器,在/system/bin目录下可以看到很多C可执行程序,如cat命令。今天,我们就来学习一下怎么在AndroID系统中添加用C语言编写的可执行程序吧。
还是以hello world来讲吧。毕竟大家对这个比较熟。
进入到AndroID源代码工程的external目录,创建hello目录,
caizd@blsx:~/mt6580_androIDL$ cd external/
caizd@blsx:~/mt6580_androIDL/external$ mkdir hello
在hello目录中新建hello.c文件,并且添加代码如下:
#include
int main(int argc,char** argv)
{
printf(“Hello World!n”);
return 0;
}
这个程序的作用是打印出Hello World!
然后在hello目录中新建AndroID.mk文件,添加代码:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODulE_Tags := optional
LOCAL_MODulE := hello
LOCAL_SRC_fileS := $(call all-subdir-c-files)
include $(BUILD_EXECUtable)
注意,BUILD_EXECUtable表示我们要编译的是可执行程序
使用mmm命令进行编译:
caizd@blsx:~/mt6580_androIDL/external$ mmm ./external/hello
编译成功后,就可以在out/target/product/inwatch_portal/system/bin/目录下,看到可执行文件hello了。
然后通过adb工具把hello push到机器的system/bin/,给755权限即可。然后执行adb 进入机器执行./hello,即可看到打印Hello World!,说明 *** 作成功。具体 *** 作命令如下:
C:Usersasus>adb root
adbd is already running as root
C:Usersasus>adb remount
remount succeeded
C:Usersasus>adb push Y:mt6580_androIDLouttargetproductinwatch_portalsystembinhello system/bin
55 KB/s (5412 bytes in 0.094s)
C:Usersasus>adb shell
root@inwatch_portal:/ # cd system/bin
cd system/bin
root@inwatch_portal:/system/bin # chmod 755 hello
chmod 755 hello
root@inwatch_portal:/system/bin # ./hello
./hello
Hello World!
root@inwatch_portal:/system/bin #
总结以上是内存溢出为你收集整理的在Android系统中用C语言来编写应用程序全部内容,希望文章能够帮你解决在Android系统中用C语言来编写应用程序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)