安卓源码怎么添加

如何在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

(随机推荐阅读本站500篇优秀文章点击前往:500篇优秀随机文章)
来源:本文由九准IT资讯原创撰写,欢迎分享本文,转载请保留出处和链接!