以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系统源码中添加一个C项目?_第1张图片

更多相关文章

  1. android 之json对象解析并展示(含json解析源码)
  2. Activity 的启动流程源码分析(Android 9.0)
  3. FrameLayout的使用——android开发之xml布局文件
  4. android中将数据写入手机内存和sdcard中的文件
  5. Android IPC 通讯机制源码分析 一
  6. android+spring boot 选择,上传,下载文件
  7. 360加固保加固的安卓/Android包,重金求APP包脱壳后的源码
  8. Eclipse下Android工程无法自动产生R文件解决

随机推荐

  1. Android仿虾米音乐播放器之通知栏notific
  2. 关于Volley网络框架的使用
  3. 广播接收者android,电话拦截广播,电话接
  4. android apk 防止反编译技术第一篇-加壳
  5. Android 6.0+新的运行时权限 开发者需要
  6. 打造android ORM框架opendroid(七)——数
  7. Android不同版本功能升级汇总
  8. android 系统核心机制binder(01)C语言简谈b
  9. Android中文API合集(6) + 开发者指南合集
  10. android service 学习(下)