打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
用android build system 编译自己的app

在system文件夹下
建立一个myinit文件夹
编辑一个init.c文件
代码如下
#include <stdio.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
int i = 0;
while (1)
{
printf("hello world (%d)",i++);
sleep(2);
}
return 0;
}

另外建立一个Android.mk 文件,内容如下
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_SRC_FILES:= \
init.c
LOCAL_MODULE:= init

LOCAL_FORCE_STATIC_EXECUTABLE := true
LOCAL_MODULE_PATH := $(TARGET_ROOT_OUT)
LOCAL_UNSTRIPPED_PATH := $(TARGET_ROOT_OUT_UNSTRIPPED)

LOCAL_STATIC_LIBRARIES := libcutils libc

#LOCAL_STATIC_LIBRARIES := libcutils libc libminui libpixelflinger_static
#LOCAL_STATIC_LIBRARIES += libminzip libunz libamend libmtdutils libmincrypt
#LOCAL_STATIC_LIBRARIES += libstdc++_static

include $(BUILD_EXECUTABLE)

在myinit文件夹下输入mm,
编译系统就会自动输出一个编译好的init程序
输出的路径也会提示出来。


-------------------------------------------------------------------------------------
Another paper in english

Add a new component into open source Android
The android build system is complicated. It is not easy to create a simple build script to build single component.

But it is much easier to add a new component into the build system. Here is a sample to build the "Hello world!"

for Android, and it is dynamic linked executable.

create a directory for the new component in $(YOUR_ANDROID)/external folder: $(YOUR_ANDROID)/external/hello
put the hello.c into the directory: $(YOUR_ANDROID)/external/hello/
create Android.mk in $(YOUR_ANDROID)/external/hello/ directory, the Android.mk likes the following:
LOCAL_PATH:=$(call my-dir)
include $(CLEAR_VARS)
LOCAL_ARM_MODE := arm
LOCAL_SRC_FILES:= \
hello.c
LOCAL_MODULE := hello
include $(BUILD_EXECUTABLE)
add the following line into $(BUILD_SYSTEM)/main.mk,$(BUILD_SYSTEM) is in $(YOUR_ANDROID)/build/core:
external/hello
launch the build command in $(YOUR_ANDROID): make hello
you will have the build target hello in $(YOUR_ANDROID)/out/target/product/generic/system/bin.
You can use include $(BUILD_SHARED_LIBRARY) to create shared library. Find more in

$(YOUR_ANDROID)/build/core/config.mk.

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Android源码编译jar包BUILD_JAVA_LIBRARY 与BUILD_STATIC_JAVA_LIBRARY的区别(一)
【转】Android 开发手记二 C可执行程序编译实例
Using pthread in Android
源码平台下JAR包的引入与编译
在Android源码里编译apk
android编译系统的makefile文件Android.mk写法
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服