如何在Android系统源码中添加一个C项目?
以hello_android为例,步骤如下:
1、在external目录下创建hello_android目录,然后在hello_android目录中编写hello_android C语言实现文件hello_android.h,hello_android.c:
(注:hello_android目录可以放置在Android系统源码下的任意目录中,并非一定要在external下。)
hello_android.h
#include<stdio.h>
#include<stdlib.h>
void makePrintf(char *str)
{
printf("%s", str);
}
hello_android.c
#include <stdio.h>
#include <stdlib.h>
#include "hello_android.h"
int main(int argc, char** argv)
{
makePrintf("hello, android!\n");
return 0;
}
2、编写负责编译的Android.mk文件:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_SRC_FILES := hello_android.c
LOCAL_C_INCLUDES += $(LOCAL_PATH)
LOCAL_MODULE := hello_android
LOCAL_MODULE_TAGS := eng
include $(BUILD_EXECUTABLE)
3、利用mm编译生成hello_android二进制可执行文件;
4、将helllo_android文件复制到/system/bin目录下执行:
#./hello_android
hello, android!
5、代码结构
$ pwd
external/hello_android
$ tree
更多相关文章
- android 之json对象解析并展示(含json解析源码)
- Activity 的启动流程源码分析(Android 9.0)
- FrameLayout的使用——android开发之xml布局文件
- android中将数据写入手机内存和sdcard中的文件
- Android IPC 通讯机制源码分析 一
- android+spring boot 选择,上传,下载文件
- 360加固保加固的安卓/Android包,重金求APP包脱壳后的源码
- Eclipse下Android工程无法自动产生R文件解决