- 浏览: 1504707 次
- 性别:
- 来自: 南京
文章分类
- 全部博客 (419)
- XMPP (19)
- Android (180)
- Java (59)
- Network (4)
- HTML5 (13)
- Eclipse (9)
- SCM (23)
- C/C++ (4)
- UML (4)
- Libjingle (15)
- Tools&Softwares (29)
- Linphone (5)
- Linux&UNIX (6)
- Windows (18)
- Google (10)
- MISC (3)
- SIP (6)
- SQLite (5)
- Security (4)
- Opensource (29)
- Online (2)
- 文章 (3)
- MemoryLeak (10)
- Decompile (5)
- Ruby (1)
- Image (1)
- Bat (4)
- TTS&ASR (28)
- Multimedia (1)
- iOS (20)
- Asciiflow - ASCII Flow Diagram Tool.htm (1)
- Networking (1)
- DLNA&UPnP (2)
- Chrome (2)
- CI (1)
- SmartHome (0)
- CloudComputing (1)
- NodeJS (3)
- MachineLearning (2)
最新评论
-
bzhao:
点赞123!
Windows的adb shell中使用vi不乱码方法及AdbPutty -
wahahachuang8:
我觉得这种东西自己开发太麻烦了,就别自己捣鼓了,找个第三方,方 ...
HTML5 WebSocket 技术介绍 -
obehavior:
view.setOnTouchListenerview是什么
[转]android 一直在最前面的浮动窗口效果 -
wutenghua:
[转]android 一直在最前面的浮动窗口效果 -
zee3.lin:
Sorry~~
When I build "call ...
Step by Step about How to Build libjingle 0.4
http://elinux.org/Android_Build_System
Android Build System
Basics of the Android Build system were described at (Down as of 9/2011): http://source.android.com/porting/build_system.html
Note that "partner-setup" should be replaced with "choosecombo" or even "lunch" in that description.
(This information seems to be duplicated at: http://pdk.android.com/online-pdk/guide/build_system.html I'm going to assume that the source.android site is the most up-to-date, but I haven't checked.)
More information about the Android build system, and some of the rationale for it, are described at: http://android.git.kernel.org/?p=platform/build.git;a=blob_plain;f=core/build-system.html
You use build/envsetup.sh to set up a "convenience environment" for working on the Android source code. This file should be source'ed into your current shell environment. After doing so you can type 'help' for a list of defined functions which are helpful for interacting with the source.
Contents[hide] |
Overview
The build system uses some pre-set environment variables and a series of 'make' files in order to build an Android system and prepare it for deployment to a platform.
Android make files end in the extension '.mk' by convention, with the main make file in any particular source directory being named 'Android.mk'.
There is only one official file named 'Makefile', at the top of the source tree for the whole repository. You set some environment variables, then type 'make' to build stuff. You can add some options to the make command line (other targets) to turn on verbose output, or perform different actions.
The build output is placed in 'out/host' and 'out/target' Stuff under 'out/host' are things compiled for your host platform (your desktop machine). Stuff under 'out/target/product/<platform-name>' eventually makes it's way to a target device (or emulator).
The directory 'out/target/product/<platform-name>/obj' is used for staging "object" files, which are intermediate binary images used for building the final programs. Stuff that actually lands in the file system of the target is stored in the directories root, system, and data, under 'out/target/product/<platform-name>'. Usually, these are bundled up into image files called system.img, ramdisk.img, and userdata.img.
This matches the separate file system partitions used on most Android devices.
Some Details
What tools are used
During the build you will be using 'make' to control the build steps themselves. A host toolchain (compiler, linker and other tools) and libraries will be used to build programs and tools that will run on the host. A different toolchain is used to compile the C and C++ code that will wind up on the target (which is an embedded board, device or the emulator). This is usually a "cross" toolchain that runs on an X86 platform, but produces code for some other platform (most commonly ARM). The kernel is compiled as a standalone binary (it does not use a program loader or link to any outside libraries). Other items, like native programs (e.g. init or toolbox), daemons or libraries will link against bionic or other system libraries.
You will be using a Java compiler and a bunch of java-related tools to build most of the application framework, system services and Android applications themselves. Finally, tools are used to package the applications and resource files, and to create the filesystem images that can be installed on a device or used with the simulator.
Telling the system where the Java toolchain is
Before you build anything, you have to tell the Android build system where your Java SDK is. (Installing a Java SDK is a pre-requisite for building).
Do this by setting a JAVA_HOME environment variable.
Specifying what to build
In order to decide what to build, and how to build it, the build system requires that some variables be set. Different products, with different packages and options can be built from the same source tree. The variables to control this can be set via a file with declarations of 'make' variables, or can be specified in the environment.
A device vendor can create definition files that describe what is to be included on a particular board or for a particular product. The definition file is called: buildspec.mk, and it is located in the top-level source directory. You can edit this manually to hardcode your selections.
If you have a buildspec.mk file, it sets all the make variables needed for a build, and you don't have to mess with options.
Another method of specifying options is to set environment variables. The build system has a rather ornate method of managing these options for you.
To set up your build environment, you need to load the variables and functions in build/envsetup.sh. Do this by 'source-ing' the file into your shell environment, like this:
$ source build/envsetup.sh
or
$ . build/envsetup.sh
You can type 'help' at this point to see some utility functions that are available to make it easier to work with the source.
To select the set of things you want to build, and what items to build for, you use either the 'choosecombo' function or the 'lunch' function. 'choosecombo' will walk you through the different items you have to select, one-by-one, while 'lunch' allows you select some pre-set combinations.
The items that have to be defined for a build are:
- the product ('generic' or some specific board or platform name)
- the build variant ('user', 'userdebug', or 'eng')
- whether you're running on a simulator ('true' or 'false')
- the build type ('release' or 'debug')
Descriptions of these different build variants are at http://source.android.com/porting/build_system.html#androidBuildVariants
The build process from a user perspective is described pretty well in this blog post: First Android platform build by CodePainters, December 2009
Actually building the system
Once you have things set up, you actually build the system with the 'make' command.
To build the whole thing, run 'make' in the top directory. The build will take a long time, if you are building everything (for example, the first time you do it).
Build tricks
Seeing the actual commands used to build the software
Use the "showcommands" target on your 'make' line:
$ make -j4 showcommands
This can be used in conjunction with another make target, to see the commands for that build. That is, 'showcommands' is not a target itself, but just a modifier for the specified build.
In the example above, the -j4 is unrelated to the showcommands option, and is used to execute 4 make sessions that run in parallel.
Make targets
Here is a list of different make targets you can use to build different parts of the system:
- make sdk - build the tools that are part of an SDK (adb, fastboot, etc.)
- make snod - build the system image from the current software binaries
- make services
- make runtime
- make droid - make droid is the normal build.
- make all - make everything, whether it is included in the product definition or not
- make clean - remove all built files (prepare for a new build). Same as rm -rf out/<configuration>/
- make modules - shows a list of submodules that can be built (List of all LOCAL_MODULE definitions)
- make <local_module> - make a specific module (note that this is not the same as directory name. It is the LOCAL_MODULE definition in the Android.mk file)
- make clean-<local_module> - clean a specific module
Speeding up the build
You can use the '-j' option with make, to start multiple threads of make execution concurrently.
In my experience, you should specify about 2 more threads than you have processors on your machine. If you have 2 processors, use 'make -j4', If they are hyperthreaded (meaning you have 4 virtual processors), try 'make -j6.
You can also specify to use the 'ccache' compiler cache, which will speed up things once you have built things a first time. To do this, specify 'export USE_CCACHE=1' at your shell command line. (Note that ccache is included in the prebuilt section of the repository, and does not have to be installed on your host separately.)
Building only an individual program or module
If you use build/envsetup.sh, you can use some of the defined functions to build only a part of the tree. Use the 'mm' or 'mmm' commands to do this.
The 'mm' command makes stuff in the current directory (and sub-directories, I believe). With the 'mmm' command, you specify a directory or list of directories, and it builds those.
To install your changes, do 'make snod' from the top of tree. 'make snod' builds a new system image from current binaries.
Setting module-specific build parameters
Some code in Android system can be customized in the way they are built (separate from the build variant and release vs. debug options). You can set variables that control individual build options, either by setting them in the environment or by passing them directly to 'make' (or the 'm...' functions which call 'make'.)
For example, the 'init' program can be built with support for bootchart logging by setting the INIT_BOOTCHART variable. (See Using Bootchart on Android for why you might want to do this.)
You can accomplish either with:
$ touch system/init/init.c $ export INIT_BOOTCHART=1 $ make
or
$ touch system/init/init.c $ m INIT_BOOTCHART=1
Makefile tricks
These are some tips for things you can use in your own Android.mk files.
build helper functions
A whole bunch of build helper functions are defined in the file build/core/definitions.mk
Try grep define build/core/definitions.mk for an exhaustive list.
Here are some possibly interesting functions:
- print-vars - shall all Makefile variables, for debugging
- emit-line - output a line during building, to a file
- dump-words-to-file - output a list of words to a file
- copy-one-file - copy a file from one place to another (dest on target?)
Add a file directly to the output area
You can copy a file directly to the output area, without building anything, using the add-prebuilt-files function.
The following line, extracted from prebuilt/android-arm/gdbserver/Android.mk copies a list of files to the EXECUTABLES directory in the output area:
$(call add-prebuilt-files, EXECUTABLES, $(prebuilt_files))
Adding a new program to build
Steps for adding a new program to the Android source tree
- make a directory under 'external'
- e.g. ANDROID/external/myprogram
- create your C/cpp files.
- create Android.mk as clone of external/ping/Android.mk
- Change the names ping.c and ping to match your C/cpp files and program name
- add the directory name in ANDROID/build/core/main.mk after external/zlib as external/myprogram
- make from the root of the source tree
- your files will show up in the build output area, and in system images.
- You can copy your file from the build output area, under out/target/product/..., if you want to copy it individually to the target (not do a whole install)
See http://www.aton.com/android-native-development-using-the-android-open-source-project/ for a lot more detail.
评论
$help
Invoke ". build/envsetup.sh" from your shell to add the following functions to your environment:
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory.
- mmm: Builds all of the modules in the supplied directories.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
Look at the source to view more functions. The complete list is:
addcompletions add_lunch_combo cgrep check_product check_variant choosecombo chooseproduct choosetype choosevariant cproj croot findmakefile gdbclient get_abs_build_var getbugreports get_build_var getprebuilt gettop godir help isviewserverstarted jgrep key_back key_home key_menu lunch _lunch m mm mmm pid printconfig print_lunch_menu resgrep runhat runtest set_java_home setpaths set_sequence_number set_stuff_for_environment settitle smoketest startviewserver stopviewserver systemstack tapas tracedmdump
发表评论
-
[Android] 为Android安装BusyBox —— 完整的bash shell
2013-12-27 10:19 1490http://www.cnblogs.com/xiaowen ... -
Windows的adb shell中使用vi不乱码方法及AdbPutty
2013-12-27 10:17 7576http://www.veryhuo.com/down/ht ... -
AppMobi推出新XDK,可创建测试PhoneGap项目
2012-09-03 13:39 2637AppMobi今天发布了一个新的工具PhoneGap Mobi ... -
Sencha
2012-09-03 12:59 1185http://www.sencha.com/ Se ... -
jQuery Mobile学习
2012-09-01 12:33 1691使用Jquery Mobile设计Android通讯录 ... -
BackBone
2012-09-01 12:34 1260Backbone.js 是一种重量级javascript M ... -
jQTouch
2012-08-30 15:57 984A Zepto/jQuery plugin for mobil ... -
SwiFTP
2012-08-30 15:43 1307SwiFTP is a FTP server that run ... -
kWS
2012-08-30 15:41 1198kWS is a lightweight and fast W ... -
jQuery Mobile
2012-08-30 15:07 1027http://jquerymobile.com/ -
PhoneGap
2012-08-30 15:07 1044http://phonegap.com/ -
Android Button background image pressed/highlighted and disabled states without
2012-08-06 12:49 1678http://shikii.net/blog/android- ... -
[AndriodTips]Image, saved to sdcard, doesn't appear in Android's Gallery app
2012-08-04 16:15 1158http://stackoverflow.com/questi ... -
Voice detection for Android
2012-07-23 11:39 2347Here it is, my fist JAVA applic ... -
[AndroidTip]local reference table overflow (max=512)的错误解决
2012-07-22 22:56 6049JNI层coding经常会遇到ReferenceTable o ... -
[AndroidTip]EditText如何初始状态不获得焦点?
2012-07-22 15:35 1226最简单的办法是在EditText前面放置一个看不到的Linea ... -
[AndroidTip]android textview滚动条
2012-07-21 14:29 1298本来是想做一个显示文字信息的,当文字很多时View的高度不能超 ... -
Google公布Android 4.1完整功能
2012-07-16 09:48 3185http://www.android.com/about/je ... -
Android开发:使用AudioTrack播放PCM音频数据【附源码】
2012-07-13 15:20 20869http://www.linuxidc.com/Linux/2 ... -
Android上的行车记录仪
2012-07-11 22:31 2010MyCar Recorder DailyRoads
相关推荐
在Android Studio中,每个项目都有一个`build.gradle`文件,用于定义项目的构建规则和依赖关系。 1. **构建过程**:Android构建系统主要包括以下几个步骤: - **配置阶段**:读取`build.gradle`文件,解析其中的...
### Android构建系统详解 #### 目标与原则 在探讨Android构建系统之前,我们先来了解其主要目标和基本原则。 **目标:** 1. **增强依赖管理可靠性:**确保当项目中的文件发生变化时,能够准确地识别出哪些部分...
Android构建系统是Android开发中的核心组成部分,它负责将源代码编译、链接并打包成可执行文件、库或APK。Android的构建系统基于Makefile系统,尤其是使用了GNU Make工具,使得开发者能够高效地管理和构建项目。 在...
根据提供的文件内容,这本书名为《Gradle Recipes for Android Master the New Build System for Android》,由Ken Kousen所著。这本书专注于教授Android开发人员如何掌握Gradle这一新的构建系统。该书是O'Reilly ...
### Android Makefile与Build System深度解析 #### 一、引言 随着移动互联网技术的快速发展,尤其是近十年间,智能手机已成为人们日常生活中不可或缺的一部分。在众多操作系统中,Google推出的Android系统因其开放...
本文将深入探讨“Android源码编译参考文档”中的关键知识点,包括高通编译参考和Android Build System。 首先,我们关注的是“高通编译参考文档”。高通是Android设备中广泛使用的芯片制造商,其编译过程涉及到特定...
在Android系统中,SystemUI是用户界面的核心组成部分,它负责管理状态栏、通知中心、快速设置等关键功能。本文将深入探讨Android 8.1版本的SystemUI源码,介绍其结构、工作原理以及如何利用提供的gradle配置进行开发...
选择`Appearance & Behavior` -> `System Settings` -> `Android SDK`,然后在`SDK Tools`选项卡中更新`build-tools`。 7. **检查Gradle配置**:确保你的`build.gradle`文件中的配置正确无误,特别是`apply plugin:...
Who This Book Is For, If you are an experienced Android developer wanting to enhance your skills with the Gradle Android build system, then this book is for you. As a prerequisite, you will need some...
If you are an experienced Android developer wanting to enhance your skills with the Gradle Android build system, then this book is for you. As a prerequisite, you will need some knowledge of the ...
同时,了解Makefile的工作原理和Android.bp(Android Build System的组件描述文件)的语法,也能提高解决问题的能力。 总的来说,Android源码编译是一个复杂而深入的过程,涉及多方面的技术知识。从源码下载、环境...
3. 在左侧导航栏中选择`Appearance & Behavior` -> `System Settings` -> `Android SDK`。 4. 在右侧的`SDK Tools`选项卡中,找到`Android SDK Build-Tools`条目。 5. 在这里,你可以勾选`25.0.2`版本,如果未安装,...
11. **Android Build System**:理解Android的构建系统(如Gradle)和Makefile,有助于自定义编译过程,提高开发效率。 12. **Android性能优化**:通过源码,可以深入分析系统如何调度线程、管理内存,从而优化应用...
本文档主要介绍如何将Android系统中的SystemUI模块导入到Eclipse中并进行编译的过程。 首先需要明确SystemUI(System User Interface)模块在Android系统中的作用。SystemUI是系统用户界面部分,它负责显示状态栏、...
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 ...
4. **Android Build System**:AOSP(Android Open Source Project)的构建系统是基于Makefile和Gradle的复杂流程,开发者需了解编译脚本和变量,以定制自己的Android系统。 5. **Bootloader和Recovery**:这部分...
首先,本书针对的是有一定Android平台开发基础和经验的开发者,他们需要了解如何使用Android Build System构建平台、如何定制和扩展系统服务,以及如何将新的硬件驱动集成进Android系统中。本书还涉及了一些高级主题...