`
helpbs
  • 浏览: 1165594 次
文章分类
社区版块
存档分类
最新评论

Android Building System 总结

 
阅读更多

转自:http://blog.csdn.net/yili_xie/article/details/5004205


花了一个月的时间来看Android Make,在网上总是看到某某大虾说一天就把Android Make overview了一下,不得不感叹现在大虾的强大和咱那连蜗牛都可以鄙视一下的进度。不过总算是彻底看清的Android make这个系统,不得不当初架构出这套机制的神人顶礼膜拜一下,虔诚地烧三柱高香,惊叹于神人的伟大的时候也越感自己的沧海一粟,苦海无边,回头无岸, 就加油滑水吧。
闲话就不多说了,来瞅瞅这套机制,Android以模块的形式来组织各个系统中的部件,Eng专业点的词汇就是Module,就是各位在几乎每个目录下都能看到的Android.mk。可以简单地把Android所有的Make文件分为4种:
1、For config
这类文件主要来配置product,board,以及根据你的Host和Target选择相应的工具以及设定相应的通用编译选项:
build/core/config.mk summary of config
build/core/envsetup.mk generate dir config and so on
build/target/product product config
build/target/board board config
build/core/combo build flags config
这里解释下这里的board和product。borad主要是设计到硬件芯片的配置,比如是否提供硬件的某些功能,比如说GPU等等,或者芯片支持浮 点运算等等。product是指针对当前的芯片配置定义你将要生产产品的个性配置,主要是指APK方面的配置,哪些APK会包含在哪个product中, 哪些APK在当前product中是不提供的。
config.mk是一个总括性的东西,它里面定义了各种module编译所需要使用的HOST工具以及如何来编译各种模块,比如说 BUILT_PREBUILT就定义了如何来编译预编译模块。envsetup.mk主要会读取由envsetup.sh写入环境变量中的一些变量来配置 编译过程中的输出目录,combo里面主要定义了各种Host和Target结合的编译器和编译选项。
2、 Module Compile
这类文件主要定义了如何来处理Module的Android.mk,以及采用何种方式来生成目标模块,这些模块生成规则都定义在config.mk里面,我们可以看看:
CLEAR_VARS:= $(BUILD_SYSTEM)/clear_vars.mk
BUILD_HOST_STATIC_LIBRARY:= $(BUILD_SYSTEM)/host_static_library.mk
BUILD_HOST_SHARED_LIBRARY:= $(BUILD_SYSTEM)/host_shared_library.mk
BUILD_STATIC_LIBRARY:= $(BUILD_SYSTEM)/static_library.mk
BUILD_RAW_STATIC_LIBRARY := $(BUILD_SYSTEM)/raw_static_library.mk
BUILD_SHARED_LIBRARY:= $(BUILD_SYSTEM)/shared_library.mk
BUILD_EXECUTABLE:= $(BUILD_SYSTEM)/executable.mk
BUILD_RAW_EXECUTABLE:= $(BUILD_SYSTEM)/raw_executable.mk
BUILD_HOST_EXECUTABLE:= $(BUILD_SYSTEM)/host_executable.mk
BUILD_PACKAGE:= $(BUILD_SYSTEM)/package.mk
BUILD_HOST_PREBUILT:= $(BUILD_SYSTEM)/host_prebuilt.mk
BUILD_PREBUILT:= $(BUILD_SYSTEM)/prebuilt.mk
BUILD_MULTI_PREBUILT:= $(BUILD_SYSTEM)/multi_prebuilt.mk
BUILD_JAVA_LIBRARY:= $(BUILD_SYSTEM)/java_library.mk
BUILD_STATIC_JAVA_LIBRARY:= $(BUILD_SYSTEM)/static_java_library.mk
BUILD_HOST_JAVA_LIBRARY:= $(BUILD_SYSTEM)/host_java_library.mk
BUILD_DROIDDOC:= $(BUILD_SYSTEM)/droiddoc.mk
BUILD_COPY_HEADERS := $(BUILD_SYSTEM)/copy_headers.mk
BUILD_KEY_CHAR_MAP := $(BUILD_SYSTEM)/key_char_map.mk
除了CLEAR_VARS是清楚本地变量之外,其他所有的都对应了一种模块的生成规则,每一个本地模块最后都会include其中的一种来生成目标模 块。大部分上面的.mk都会包含base_rules.mk,这是对模块进行处理的基础文件,建议要写本地模块的都去看看,看明白了为什么 Android.mk要这么写就会大致明白了。
3、Local Module
本地模块的Makefile文件就是我们在Android里面几乎上随处可见的Android.mk。Android进行编译的时候会通过下面的函数来 遍历所有子目录中的Android.mk,一旦找到就不会再往层子目录继续寻找(所有你的模块定义的顶层Android.mk必须包含自己定义的子目录中 的Android.mk)。
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
不同类型的本地模块具有不同的语法,但基本上是相通的,只有个别变量的不同,如何添加模块在前面的帖子已经说过了,大家可以参考。
Android通过LOCAL_MODULE_TAGS来决定哪些本地模块会不会编译进系统,通过PRODUCT和LOCAL_MODULE_TAGS来 决定哪些应用包会编译进系统,如果用户不指定LOCAL_MODULE_TAGS,默认它的值是user。此外用户可以通过buildspec.mk来指 定你需要编译进系统的模块。
用户也可以通过mm来编译指定模块,或者通过make clean-module_name来删除指定模块。
4、Package
这主要指的是build/core/Makefile这个文件,它定义了生成各种img的方式,包括ramdisk.img userdata.imgsystem.imgupdate.ziprecover.img等。我们可以看看这些img都是如何生成的,对 应着我们常用的几个make goals:

makegoals

在实际的过程中,我们也可以自己编辑out目录下的生成文件,然后手工打包相应生成相应的img,最常用的是加入一些需要集成进的prebuilt file。

所有的Makefile都通过build/core/main.mk这个文件组织在一起,它定义了一个默认goals:droid,当我们在TOP目录下 敲Make实际上就等同于我们执行make droid。当Make include所有的文件,完成对所有make我文件的解析以后就会寻找生成droid的规则,依次生成它的依赖,直到所有满足的模块被编译好,然后使用 相应的工具打包成相应的img。

基本上Android building system就是以这样一种方式组织在一起的了,下面说一点闲散的东西。首先是如何来加快Android的编译过程,因为每次Android都要遍历所有 的Android.mk,不管是编译整个工程还是只编译某个模块。所以可以将遍历的结果保存下来,下次直接从文件读就好了,但是这里容易出错,所以一定要 确认是否正确包含了所有的.mk,当新加入文件的时候确认将原来保存的文件删除。下面是我写的加快编译的一个makefile,将下面的语句替换掉 main.mk中的相应部分就可以了:
FROM:
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
TO:
ifneq ($(ONE_SHOT_MAKEFILE),)
else
ifneq ($(CASH_MK),true)
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
else
subdir-makefiles-cash := $(shell cat build/subdir_mk_cash)
ifeq ($(subdir-makefiles-cash),)
$(warning No .mk cash ,create now !)
subdir_makefiles += /
$(shell build/tools/findleaves.sh --prune="./out" $(subdirs) Android.mk)
mk-to-file := $(shell echo $(subdir_makefiles) > build/subdir_mk_cash)
else
$(warning Using cash mk !)
subdir_makefiles := $(shell cat build/subdir_mk_cash)
endif
endif
endif
通过CASH_MK=true来打开快速编译的功能,因为没有对错误进行检测的操作,所以使用的时候一定要特别小心。

最后一个是扩展SDK API的问题,Android可以编译出自己的SDK,并扩展相应的SDK API,现在没有仔细的研究,只了解一个粗暴的方法就是在frameworks/base/core/java中添加相应的类。将来有时间的话再仔细研究 下~~


分享到:
评论

相关推荐

    Gradle Recipes for Android Master the New Build System for Android pdf 0分

    Gradle Recipes for Android Master the New Build System for Android 英文pdf

    Embedded Programming with Android: Bringing Up an Android System from Scratch

    Step by step, he guides you through building a system with all the key components Android hardware developers must deliver to manufacturing. By the time you’re done, you’ll have the key programming...

    Learning.Java.by.Building.Android.Games

    Android is the fastest growing operating system (OS) with one of the largest installed bases of any mobile OS. Android uses one of the most popular programming languages, Java, as the primary language...

    Building Android Apps with HTML, CSS, and JavaScript

    This book received valuable community input through O’Reilly’s Open Feedback Publishing System (OFPS). Learn more at http://labs.oreilly.com/ofps.html. CSDN上见到过这个资源但无法下载,自己上传一个

    Building Android Apps with HTML,CSS,and.JavaScript(2nd,2012.01)

    Discover why device-agnostic mobile apps are the wave of the future, and start building apps that offer greater flexibility and a broader reach. Learn the basics for making a web page look great on...

    Learning Android

    If you're new to the Android mobile operating system, Learning Android is the perfect way to master the fundamentals. Written by an expert who's taught Android to thousands of people in large ...

    Android Platform Developer‘s Guide.doc

    Android Build System 4 In this document 4 Building the Android Platform 6 Building the Android Kernel 8 Build Variants 9 Configuring a New Product 10 In this document 10 Detailed Instructions 11 New ...

    Android.SQLite.Essentials.1783282959

    Android SQLite Essentials focuses on the core concepts behind building database-driven applications. This book covers the basic and advanced topics with equivalent simplicity and detail, in order to ...

    Introduction.to.Android.Application.Development(4th,2013.12) pdf

    Building Your First Android Application 68 Creating and Configuring a New Android Project 69 Core Files and Directories of the Android Application 73 Creating an AVD for Your Project 75 Creating a ...

    Android programming for beginners

    Book Details ISBN 139781785883262 Paperback 698 pages Book Description ...By the end of this book, you’ll be ready to start building your own custom applications in Android and Java.

    App.Inventor.2.Building.Android.Apps.B0193RHQG6

    App Inventor 2 Building Android Apps takes you step-by-step through the whole process of designing and creating your first two android apps using the free MIT App Inventor 2 software. The book is ...

    Beginning.Android.5th.Edition.1430246863

    Google’s Android operating-system has taken the industry by storm, going from its humble beginnings as a smartphone operating system to its current status as a platform for apps that run across a ...

    Mastering Android Game Development with Unity

    You will begin with the basic concepts of Android game development, a brief history of Android games, the building blocks of Android games in Unity 5, and the basic flow of games. You will configure ...

    Learning Android: Develop Mobile Apps Using Java and Eclipse(第二版)

    Alarms and System Services Broadcasting Intents Summary Chapter 14 App Widgets Using Content Providers Through Widgets Summary Chapter 15 Networking and Web Overview Quick Example Networking Basics ...

    Mastering.Android.Game.Development.1783551771

    Learn the internals of a game engine by building one A succinct, hands-on guide to enhance your game development skills with Android SDK Who This Book Is For If you are an intermediate-level Android ...

    Pro OpenGL ES For Android

    In Pro OpenGL ES for Android, you'll find out how to harness the full power of OpenGL ES, and design your own 3D applications by building a fully-functional 3D solar system model using Open GL ES!...

    Android.6.Essentials.1785884417

    Android 6 is the latest and greatest version of the Android operating system, and comes packed with cutting edge new features for you to harness for the benefit of building better applications. ...

    Pro OpenGL ES for Android

    In Pro OpenGL ES for Android, you'll find out how to harness the full power of OpenGL ES, and design your own 3D applications by building a fully-functional 3D solar system model using Open GL ES!...

    Exploring SE for Android 无水印书签修正版pdf

    Their positions range from hobbyists wanting to secure their Android powered creations to OEM engineers building handsets to engineers of emerging areas where Android is seeing growth. What You Will...

Global site tag (gtag.js) - Google Analytics