`

[转]下载并编译Android 2.3源码

阅读更多
原文http://www.blogjava.net/TiGERTiAN/archive/2011/01/20/343283.html

前几天下载了Android 2.3.1的源代码并在Ubuntu 10.04(32位)上编译通过。这篇文章简要记录了下载、编译的过程。

关于搭建Android开发环境的文章已经有很多,本文只简要介绍一下,做为备忘。

[ 编译前的准备 ]

这一步安装获取源代码以及编译所需要的软件,使用如下命令:

$ sudo aptitude install git-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
另外,参考别人编译Android 2.3的经验,安装了下列软件包:

$ sudo apt-get install lib64z1-dev libc6-dev-amd64 g++-multilib lib64stdc++6
虽然Android官方网站上讲不支持Java 6,不过我使用Java 6也可以编译通过,所以在这里Easwy安装的是Java 6。首先去掉/etc/apt/sources.list中这两行的注释,使能Java 6源:

deb http://archive.canonical.com/ubuntu lucid partner
deb-src http://archive.canonical.com/ubuntu lucid partner
然后安装Java 6 JDK:

$ sudo aptitude install sun-java6-jdk
接下来下载repo工具,这是Google提供的一个Python脚本,方便管理多个Git版本库:

$ cd ~
$ mkdir bin
$ curl http://android.git.kernel.org/repo >~/bin/repo
$ chmod a+x ~/bin/repo
记得把repo加到你的路径中,方便以后使用。编辑~/.bashrc,加入下面一行:

PATH=$PATH:~/bin
export PATH
然后用命令. ~/.bashrc,以后就可以直接使用repo命令了。

接下来获取Android 2.3.1的源代码:

$ mkdir mydroid
$ cd mydroid
$ repo init -u git://android.git.kernel.org/platform/manifest.git -b android-2.3.1_r1
$ repo sync
[ 编译Android ]

接下来开始编译:

$ make -j`grep '^processor' /proc/cpuinfo | wc -l`
上面的命令中,-j参数告诉make启动多个并行任务进行编译,在支持多核的CPU上能加快编译速度。如果你知道你CPU是几核的,可以直接把这部分替换成-j2(双核)。

我在编译的过程中遇到下面的错误:

************************************************************

You are attempting to build on a 32-bit system.

Only 64-bit build environments are supported beyond froyo/2.2.

************************************************************

这是因为在Makefile中检测了CPU的字长。我直接把build/core/main.mk中下面的话注释掉:

#ifneq (64,$(findstring 64,$(build_arch)))
#$(warning ************************************************************)
#$(warning You are attempting to build on a 32-bit system.)
#$(warning Only 64-bit build environments are supported beyond froyo/2.2.)
#$(warning ************************************************************)
#$(error stop)
#endif
接下来又遇到下面的错误:

Docs droiddoc: out/target/common/docs/api-stubs

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib

make: *** [out/target/common/docs/api-stubs-timestamp] Error 45

make: *** Waiting for unfinished jobs….

Could not load ‘clearsilver-jni’

java.library.path = out/host/linux-x86/lib

make: *** [out/target/common/docs/doc-comment-check-timestamp] Error 45

这是由于clearsilver在编译时如果检测到使用Java JDK 6,就使用64位编译。要避开此错误,需要修改下面四个文件:

external/clearsilver/cgi/Android.mk
external/clearsilver/java-jni/Android.mk
external/clearsilver/util/Android.mk
external/clearsilver/cs/Android.mk
把这四个Makefile中的下列语句注掉即可:

# This forces a 64-bit build for Java6
# Comment by Easwy
# LOCAL_CFLAGS += -m64
# LOCAL_LDFLAGS += -m64
然后在external/clearsilver目录中执行一下make clean,然后回到项目根目录,继续make即可。

当编译完成时,生成的image文件放在out/target/product/generic目录中。
分享到:
评论
3 楼 w11h22j33 2011-01-22  
2 楼 w11h22j33 2011-01-22  
Building, running, and debugging Android source

There is a lot of confusion surrounding the work flow in the Android source tree, so allow me to simplify:

Follow the initial instructions for downloading the source at:
http://source.android.com/download

Set up your environment to build the engineering build for the generic device and generic product. This is similar to the SDK, but with a few pieces missing.

$ source build/envsetup.sh
$ lunch 1
To build for the first time:
$ make

If you have a multi-core system, you can build with make -jN where N is twice the number of cores on your machine. This should speed up the first build considerably.

To launch the emulator from your build:
$ ./out/host/<your-machine-type>/bin/emulator

On my system <your-machine-type> is linux-x86.

NOTE: The emulator knows where to find system and data images as a result of running lunch 1 above. This sets the environment variable ANDROID_PRODUCT_OUT to point to the target directory. For this example, it should be out/target/product/generic/.

If you wish to make changes to the source code, there are handy utilities that have been exposed to your environment by source build/envsetup.sh above. For example, if you modify the Email app and just want to rebuild it:
$ mmm packages/apps/Email

To see your changes in the emulator you can run:
$ adb remount
$ adb sync

Which will copy the regenerated Email.apk file into the emulator’s /system/app folder, triggering the PackageManager to automatically reinstall it.

Or if you change framework resources in frameworks/base/core/res/res/ you could regenerate framework-res.apk with:
$ mmm frameworks/base/core/res

Or if you modified even the framework itself you could run:

$ ONE_SHOT_MAKEFILE="frameworks/base/Android.mk" make framework

This is a special variation of mmm which is used to build frameworks/base/core/java.

To sync these changes you must restart the running framework and sync, as with this handy sequence:

$ adb remount
$ adb shell stop
$ adb sync
$ adb shell start

Finally, to debug your changes you can use the DDMS tool to select a process for debug and then attach Eclipse to it. If you have the Eclipse Android Development plugin installed, there is a special DDMS perspective which you can use to choose the process for debug. To attach Eclipse to it, see these instructions:
http://source.android.com/using-eclipse

This document also describes how to use Eclipse for development. Any IDE should work with the proper finagling though. Just note that the IDE won’t really by an integrated environment, the final output of APKs, system.img, and even the generation of R.java files will have to be done by make!

A note about the processes in Android:

system_process houses all things under frameworks/base/services. This includes the PackageManagerService, StatusBarService, etc. It has many, many threads (one for each service, and then one main UI thread), so be wary when debugging.
com.android.acore hosts Launcher (home), Contacts, etc. You can determine the apps/providers that run here by looking forandroid:process="android.process.acore" in the various AndroidManifest.xml files in packages/.
Also remember that the “framework” (under frameworks/base/core/java) is not hosted by any one process. It is a library used by most processes, so to debug code there you can usually use a simple demo app that takes advantage of whatever you changed and debug that app’s process. A useful trick for setting up your debug connection is to call Debug.waitForDebugger() during some startup part of an application or system service.
1 楼 w11h22j33 2011-01-22  
Git 是 Linux Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的分布式版本控制软件,它不同于Subversion、CVS这样的集中式版本控制系统。在集中式版本控制系统中只有一个仓 库(repository),许多个工作目录(working copy),而像Git这样的分布式版本控制系统中(其他主要的分布式版本控制系统还有BitKeeper、Mercurial、GNU Arch、Bazaar、Darcs、SVK、Monotone等),每一个工作目录都包含一个完整仓库,它们可以支持离线工作,本地提交可以稍后提交到服务器上。分布式系统理论上也比集中式的单服务器系统更健壮,单服务器系统一旦服务器出现问题整个系统就不能运行了,分布式系统通常不会因为一两个节点而受到影响。
因为Android是由kernel、Dalvik、Bionic、prebuilt、build等多个Git项目组成,所以Android项目编写了一个名为Repo的Python的脚本来统一管理这些项目的仓库,使得Git的使用更加简单。
这几天William为了拿Android最新的sourcecode,学习了一下git和repo的一些基本操作,整理了一个如何取得Android代码的How-To,今天把他贴上来。
1、Git的安装
在Ubuntu 8.04上安装git只要设定了正确的更新源,然后使用apt-get就可以了,有什么依赖问题,就让它自己解决吧。其中cURL是一个利用URL语法在命令行下工作的文件传输工具,会在后面安装Repo的时候用到。
sudo apt-get install git-core curl
2、安装Repo
首先确保在当前用户的主目录下创建一个/bin目录(如果没有的话),然后把它(~/bin)加到PATH环境变量中
接下来通过cURL来下载Repo脚本,保存到~/bin/repo文件中
curl http://android.git.kernel.org/repo >~/bin/repo
别忘了给repo可执行权限
chmod a+x ~/bin/repo
3、初始化版本库
如果是想把Android当前主线上最新版本的所有的sourcecode拿下来,我们需要repo的帮助。
先建立一个目录,比如~/android,进去以后用repo init命令即可。
repo init -u git://android.git.kernel.org/platform/manifest.git
这个过程会持续很长的时间(至少可以好好睡一觉),具体要多少时间就取决于网络条件了
最后会看到 repo initialized in /android这样的提示,就说明本地的版本库已经初始化完毕,并且包含了当前最新的sourcecode。
如果想拿某个branch而不是主线上的代码,我们需要用-b参数制定branch名字,比如:
repo init -u git://android.git.kernel.org/platform/manifest.git -b cupcake
另一种情况是,我们只需要某一个project的代码,比如kernel/common,就不需要repo了,直接用Git即可。
git clone git://android.git.kernel.org/kernel/common.git
这也需要不少的时间,因为它会把整个Linux Kernel的代码复制下来。
如果需要某个branch的代码,用git checkout即可。比如我们刚刚拿了kernel/common.get的代码,那就先进入到common目录,然后用下面的命令:
git checkout origin/android-goldfish-2.6.27 -b goldfish
这样我们就在本地建立了一个名为goldfish的android-goldfish-2.6.27分支,代码则已经与android-goldgish-2.6.27同步。我们可以通过git branch来列出本地的所有分支。
4、同步版本库
使用epo sync命令,我们把整个Android代码树做同步到本地,同样,我们可以用类似
repo sync project1 project2 …
这样的命令来同步某几个项目
如果是同步Android中的单个项目,只要在项目目录下执行简单的
git pull
即可。
5、通过GitWeb下载代码
另外,如果只是需要主线上某个项目的代码,也可以通过GitWeb下载,在shortlog利用关键字来搜索特定的版本,或者找几个比较新的tag来下载还是很容易的。
Git最初是为Linux内核开发而设计,所以对其他平台的支持并不好,尤其是Windows平台,必须要有Cygwin才可以。现在,得益于msysgit项目,我们已经可以不需要Cygwin而使用Git了。另外,Git Extensions是一个非常好用的Windows Shell扩展,它能与资源管理器紧密集成,甚至提供了Visual Studio插件。它的官方网站上有一分不错的说明文档,感兴趣的朋友可以看一看。
至于Git的参考文档,我推荐Git Magic,这里还有一个Git Magic的中文版。

相关推荐

    Ubuntu10.10(64位)编译Android2.3源码 遇到的错误

    Ubuntu10.10(64位)编译Android2.3源码 遇到的错误

    Ubuntu-32位机安装编译Android2.3源码及内核

    Ubuntu-32位机安装编译Android2.3源码及内核,启动模拟器器,及生成SDK等。及编译过程中遇见相关问题解决

    Ubuntu平台下Android2.3源码下载编译全过程

    Ubuntu平台下Android2.3源码下载编译全过程

    Ubuntu-32位机安装编译Android2.3源码及内核.doc

    Ubuntu-32位机安装编译Android2.3源码及内核

    android4.0源码编译

    android4.0,android2.3,android2.2,android源码编译,有效果图,可以自己看啊。如果你们编译中间出了问题可以跟我联系。

    busybox for android(passed in android 2.3)

    1. 下载cyanogenmod修改过的busybox源码(即此源码,来源:https://github.com/CyanogenMod/android_external_busybox)并解压到源码external/busybox目录 2. 编译busybox并修正编译错误: 先在android源码根目录执行...

    opengl_nehe_android_源码

    包括:01: Hello OpenGL,02: 多边形,03: 颜色,04: 旋转,05: 3D 空间,06: 纹理映射,07: 光照,08: 混合,09: 移动图像,10: 加载模型,11: 飘动的旗帜,16: 雾!...在Android2.3源码下能编译运行

    Android4.3_r2.3编译的framework_intermediates等jar包

    安卓4.3_r2.3源码编译出来的几个jar包,包括bouncycastle_intermediates/classes.jar、core_intermediates/classes.jar、framework_intermediates/classes.jar

    Android应用程序开发宝典

    1-1-1 编译Android2.3 形成文件系统 1-1-2 编译Android2.3 形成SDK 开发包 1-2 安装开发工具,设置开发环境 1-2-1 安装Eclipse 1-2-2 安装ADT 1-2-3 设置开发环境 1-2-4 运行Android 模拟器 ···········...

    疯狂Android讲义源码

     1.3.5 使用DX编译Android应用 18  1.3.6 使用Android Asset Packaging  Tool(AAPT)打包资源 19  1.3.7 使用mksdcard管理虚拟SD卡 19  1.4 开始第一个Android应用 20  1.4.1 使用Eclipse开发第一个  ...

    openscenegraph(osg)3.2.1rc1 android静态库 http://521.be

    本附件为下载地址,不是附件本身,基于osg最新版3.2.1rc1(http://www.openscenegraph.org/index.php/download-section/stable-releases/149-openscenegraph-3-2-1-release-candidate-1),基本android2.3版本编译。...

    《深度理解Android:第一卷》

    1.2.1 下载源码 / 4 1.2.2 编译源码 / 6 1.3 工具介绍 / 8 1.3.1 Source Insight介绍 / 8 1.3.3 Busybox的使用 / 11 1.4 本章小结 / 12 第2章 深入理解JNI / 13 2.1 JNI概述 / 14 2.2 学习JNI的实例:...

    Android笔记之:CM9源码下载与编译的应用

    上一篇文章是android2.3的编译,已经过时,而且现在ubuntu已经升级到12.04,等等之类的,使我觉得非常有必要重新写一篇新的博客来展示最新的android怎么在最新的ubuntu上编译。基于以上几点,下面我将基于galaxys2来...

    Android应用源码简.美音乐播放器开发项目

    如果模拟器上自己没有上传音乐就会强制退出,所以最好用真机测试,本音乐播放器是在Android2.3下开发的,适配问题没有做好,还有程序中的一些性能优化也没有做,这个播放器是提供给初学者一个参考。源码有比较详细的...

    《Android应用开发揭秘》源码

     2.3 创建第一个Android项目——HeUoAndroid  2.3.1 创建HelloAndroid项目  2.3.2 运行HelloAndroid及模拟器的使用  2.3.3 调试HelloAndroid  2.4 小结  第二部分 基础篇  第3章 Android程序设计基础  3.1 ...

    ArcGIS for Android 100.4.0示例完整源码

    ArcGIS for Android 100.4.0示例完整源码,采用离线配置aar文件,使用android studio2.3编辑器,编译android SDK版本25。

    android studio2.3如何编译动态库的过程详解

    最近在工作中需要编译android下的动态库,本以为是一件简单的事,没想到因为工具,以及google本身被墙的原因,折腾了好久。 在windows外的平台搞事情,寿命都得缩短。 过程如下 一种方案是用eclipse+ndk+adt插件,...

    Android系统源代码情景分析-罗升阳-源码

    1.3.2 编译Android源代码 1.3.3 运行Android模拟器 1.4 下载、编译和运行Android内核源代码 1.4.1 下载Android内核源代码 1.4.2 编译Android内核源代码 1.4.3 运行Android模拟器 1.5 开发第一个Android应用...

    安卓平台客户端-服务器socket通信_源码带注释

    移动客户端在Android平台下、服务器端使用纯JAVA语言的socket通信开发。子文件夹按单线程和多线程、客户端和服务器端分类,代码包含...在移动端为Android 2.3手机、服务器端为WINDOWS PC的环境下真机亲测,运行无误。

    Android技术内幕.系统卷(扫描版)

    1.2 获取和编译android的源码 /13 1.2.1 环境配置 /13 1.2.2 获取android源码 /14 1.2.3 编译android的源码及其工具包 /16 1.2.4 运行android系统 /21 1.3 开发环境搭建 /23 1.3.1 应用开发环境搭建 /23 1.3.2 源码...

Global site tag (gtag.js) - Google Analytics