C/C++编写Android系统应用程序模块
2016-05-30 15:25
519 查看
1、在Android源代码工程环境中,可以用C/C++语言编写应用程序模块(可执行程序或者动态链接库so)。这些模块的源代码一般位于external目录下,编译结果一般位于/system/bin或者/system/lib目录下。
2、Hello Word程序示例
2.1、代码结构
源代码根--|
|--external--|
|--hello_word--|
|--hello.c
|--Android.mk
2.2 hello.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
printf("hello word");
return 1;
}
2.3 Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello_word_test
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)
2.4用mmm命令编译,用make snod打包
注意mmm命令不是直接可用的,必须先在 源代码根/build 下执行source envsetup.sh之后再使用。
在 源代码根下执行 mmm ./external/hello_word/
执行完mmm之后,就可以看到 源代码根/out/target/product/generic/system/bin 下有 hello_word_test 可执行文件。
在 源代码根下执行 make snod
在执行完make命令打包之后,这个可执行文件就打包进了 源代码根/out/target/product/generic/system.img 镜像文件中去了。
2.5验证
用模拟器加载打包好的镜像文件,启动模拟器,用adb shell连接上,在/system/bin里面执行 ./hello_word_test即可以看到运行结果。
2.6 C++语言
main.cpp文件
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout<<"hello,this is my first linux test."<<endl;
return 1;
}
Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello_word_cpp
LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
include $(BUILD_EXECUTABLE)
2、Hello Word程序示例
2.1、代码结构
源代码根--|
|--external--|
|--hello_word--|
|--hello.c
|--Android.mk
2.2 hello.c
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv){
printf("hello word");
return 1;
}
2.3 Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello_word_test
LOCAL_SRC_FILES := $(call all-subdir-c-files)
include $(BUILD_EXECUTABLE)
2.4用mmm命令编译,用make snod打包
注意mmm命令不是直接可用的,必须先在 源代码根/build 下执行source envsetup.sh之后再使用。
在 源代码根下执行 mmm ./external/hello_word/
执行完mmm之后,就可以看到 源代码根/out/target/product/generic/system/bin 下有 hello_word_test 可执行文件。
在 源代码根下执行 make snod
在执行完make命令打包之后,这个可执行文件就打包进了 源代码根/out/target/product/generic/system.img 镜像文件中去了。
2.5验证
用模拟器加载打包好的镜像文件,启动模拟器,用adb shell连接上,在/system/bin里面执行 ./hello_word_test即可以看到运行结果。
2.6 C++语言
main.cpp文件
#include<iostream>
using namespace std;
int main(int argc, char *argv[])
{
cout<<"hello,this is my first linux test."<<endl;
return 1;
}
Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE_TAGS := optional
LOCAL_MODULE := hello_word_cpp
LOCAL_SRC_FILES := $(call all-subdir-cpp-files)
include $(BUILD_EXECUTABLE)
相关文章推荐
- 使用C++实现JNI接口需要注意的事项
- Android IPC进程间通讯机制
- Android Manifest 用法
- [转载]Activity中ConfigChanges属性的用法
- Android之获取手机上的图片和视频缩略图thumbnails
- Android之使用Http协议实现文件上传功能
- Android学习笔记(二九):嵌入浏览器
- android string.xml文件中的整型和string型代替
- i-jetty环境搭配与编译
- android之定时器AlarmManager
- android wifi 无线调试
- Android Native 绘图方法
- Android java 与 javascript互访(相互调用)的方法例子
- android 代码实现控件之间的间距
- android FragmentPagerAdapter的“标准”配置
- Android"解决"onTouch和onClick的冲突问题
- android:installLocation简析
- android searchView的关闭事件
- SourceProvider.getJniDirectories