编译Android源代码
很久之前就想编译Android源代码试试,一直没有尝试,这几天利用业余时间尝试编译一下Android源代码。
虽然网络上有很多作者,写过编译Android源代码的过程,基本上是照葫芦画瓢,可以参见官方给出的文档(https://source.android.com/source/building.html),我觉得所看不如所做。基本上在编译之路上遇到的
种种问题,官方并未给的很详细的说明解释,在此记录自己编译的过程。
编译需要的硬件配置:
(1)一台性能稍好的电脑(我的电脑联想天逸F41 Pentium T220,7年前购得)
(2)留给足够多的硬盘空间>40G
官方给的解释:
A Linux or Mac system. It is also possible to build Android in a virtual machine on unsupported systems such as Windows.
If you are running Linux in a virtual machine, you need at least 16GB of RAM/swap and 30GB or more of disk space
in order to build the Android tree.
大家看到内存16G或交换空间, 大于30G 硬盘。傻了,其实官方说明的是,如果你Build Android Tree
也就是全系列的Android源代码,这个是基本要求。
我的编译环境
硬件:内存 3G
虚拟机 VM10 + Debian (机器允许最好安装 Ubuntu 最新 64位系统)
虚拟机配置: 虚拟机分配内存 > 2G , 硬盘空间 > 40G
(因为天朝封锁了Google的全部服务,下载Android 源代码需要翻墙。我的机器也装有Linux双系统,因为
Linux 系统下 翻墙 ,我用的是 IKEv2 / IPSec 翻墙技术,但是Linux Ubuntu 我不知道如何配置,也没有
在网上找到解决方案,所以在Windows系统下装虚拟机,间接翻墙。PPTP/L2Tp都极不稳定,不推荐)
(3)源代码4.X 系列的大小 > 35G , 另外你还需要预留一部分空间作为编译之用。我的电脑硬盘所剩空间
只有42G,分40G给虚拟机。
软件环境配置
官方给出的如下:
基本配置 :
- Python 2.6 -- 2.7, which you can download from python.org.
- GNU Make 3.81 -- 3.82, which you can download from gnu.org,
- JDK 7 to build the master branch of Android in the Android Open Source Project (AOSP); JDK 6 to build Gingerbread through KitKat; JDK 5 for Cupcake through Froyo. See Initializing a Build Environment for installation instructions by operating system.
- Git 1.7 or newer. You can find it at git-scm.com.
补充一下:
JDK7是编译Android 4.X 系统所要求的,你编译的Android系统不同所需要的JDK版本也不同,官方解释:
To develop older versions of Android, download and install the corresponding version of the Java JDK:
Java 6: for Gingerbread through KitKat
Java 5: for Cupcake through Froyo
我编译的是Android 1.6 JDK 5
补充说明: 如果机器已经装有JDK6, 需要JDK5 编译,那么可以更改机器Java运行的默认版本号
方法: 1 查看Java版本 java - version , javac -version
2. 更改默认版本 ,依次更改 Java javac 默认 版本
sudo update-alternatives --config java
参见 (http://askubuntu.com/questions/121654/how-to-set-default-java-version)
添加编译库
官方解释
Installing required packages (Ubuntu 12.04)
You will need a 64-bit version of Ubuntu. Ubuntu 12.04 is recommended. Building using an older version of Ubuntu is not supported on master or recent releases.
$ sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
$ sudo ln -s /usr/lib/i386-linux-gnu/mesa/libGL.so.1 /usr/lib/i386-linux-gnu/libGL.so
Installing required packages (Ubuntu 10.04 -- 11.10)
Building on Ubuntu 10.04-11.10 is no longer supported, but may be useful for building older releases of AOSP.
$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
zip curl zlib1g-dev libc6-dev lib32ncurses5-dev ia32-libs \
x11proto-core-dev libx11-dev lib32readline5-dev lib32z-dev \
libgl1-mesa-dev g++-multilib mingw32 tofrodos python-markdown \
libxml2-utils xsltproc
On Ubuntu 10.10:
$ sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
On Ubuntu 11.10:
$ sudo apt-get install libx11-dev:i386
加注: 官方列出了各个版本所需要的库,推荐大家选取各自所需
我的虚拟机是 Debian 7 32位操作系统我的安装库
$ sudo apt-get install git gnupg flex bison gperf build-essential \
zip curl libc6-dev libncurses5-dev:i386 x11proto-core-dev \
libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-glx:i386 \
libgl1-mesa-dev g++-multilib mingw32 tofrodos \
python-markdown libxml2-utils xsltproc zlib1g-dev:i386
其中lib32ncurses5-dev 等几个库 没有自动检索到,不要急,接着我们执行
sudo apt-get install libx11-dev:i386
如果你的机器是官方介绍的64位Ubuntu系统,那么直接按照官方操作,重复安装的库不会重叠。接着链接
sudo ln -s /usr/lib32/mesa/libGL.so.1 /usr/lib32/mesa/libGL.so
配置 USB Access 可以参照官方解释 我贴一下别人写的,因为自己没有配置这一项,这个是为了开发测试,
而如果你开发用了Android Eclipse 那一套东西,再此配置便是多余,贴一下
(别人写的,和官方一样)
因為linux預設無法access到USB device,
所以得加一些udev的rule,
先在udev底下建立一個檔案,
所以得加一些udev的rule,
先在udev底下建立一個檔案,
1 | sudo vim /etc/udev/rules.d/ 51 -android.rules |
然後貼入下列的內容!注意!!請把owner改成你自己的ubuntu user name!
01 | # adb protocol on passion (Nexus One) |
02 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e12" , MODE= "0600" , OWNER= "ken" |
03 | # fastboot protocol on passion (Nexus One) |
04 | SUBSYSTEM== "usb" , ATTR{idVendor}== "0bb4" , ATTR{idProduct}== "0fff" , MODE= "0600" , OWNER= "ken" |
05 | # adb protocol on crespo/crespo4g (Nexus S) |
06 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e22" , MODE= "0600" , OWNER= "ken" |
07 | # fastboot protocol on crespo/crespo4g (Nexus S) |
08 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e20" , MODE= "0600" , OWNER= "ken" |
09 | # adb protocol on stingray/wingray (Xoom) |
10 | SUBSYSTEM== "usb" , ATTR{idVendor}== "22b8" , ATTR{idProduct}== "70a9" , MODE= "0600" , OWNER= "ken" |
11 | # fastboot protocol on stingray/wingray (Xoom) |
12 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "708c" , MODE= "0600" , OWNER= "ken" |
13 | # adb protocol on maguro/toro (Galaxy Nexus) |
14 | SUBSYSTEM== "usb" , ATTR{idVendor}== "04e8" , ATTR{idProduct}== "6860" , MODE= "0600" , OWNER= "ken" |
15 | # fastboot protocol on maguro/toro (Galaxy Nexus) |
16 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e30" , MODE= "0600" , OWNER= "ken" |
17 | # adb protocol on panda (PandaBoard) |
18 | SUBSYSTEM== "usb" , ATTR{idVendor}== "0451" , ATTR{idProduct}== "d101" , MODE= "0600" , OWNER= "ken" |
19 | # adb protocol on panda (PandaBoard ES) |
20 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "d002" , MODE= "0600" , OWNER= "ken" |
21 | # fastboot protocol on panda (PandaBoard) |
22 | SUBSYSTEM== "usb" , ATTR{idVendor}== "0451" , ATTR{idProduct}== "d022" , MODE= "0600" , OWNER= "ken" |
23 | # usbboot protocol on panda (PandaBoard) |
24 | SUBSYSTEM== "usb" , ATTR{idVendor}== "0451" , ATTR{idProduct}== "d00f" , MODE= "0600" , OWNER= "ken" |
25 | # usbboot protocol on panda (PandaBoard ES) |
26 | SUBSYSTEM== "usb" , ATTR{idVendor}== "0451" , ATTR{idProduct}== "d010" , MODE= "0600" , OWNER= "ken" |
27 | # adb protocol on grouper/tilapia (Nexus 7 ) |
28 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e42" , MODE= "0600" , OWNER= "ken" |
29 | # fastboot protocol on grouper/tilapia (Nexus 7 ) |
30 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4e40" , MODE= "0600" , OWNER= "ken" |
31 | # adb protocol on manta (Nexus 10 ) |
32 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4ee2" , MODE= "0600" , OWNER= "ken" |
33 | # fastboot protocol on manta (Nexus 10 ) |
34 | SUBSYSTEM== "usb" , ATTR{idVendor}== "18d1" , ATTR{idProduct}== "4ee0" , MODE= "0600" , OWNER=“ken" |
至此 准备工作完成了一半,接下来见文章二