准备工作:
安装JDK: 因为我是编译android4.4,故jdk6即可满足。ubuntu14.04不支持apt-get安装,我们来手动安装一下:
自己去oracle的官网下载安装包,我下载的是:jdk-6u45-linux-x64.bin
。
将文件copy到虚拟机的 /usr/lib/jvm/java 目录,执行如下命令安装:
sudo chmod u+x /usr/lib/jvm/java/jdk1.6.5_45.bin/usr/lib/jvm/java/jdk1.6.5_45.bin
安装完毕后在同级目录下会产生jdk1.6.5xxx文件。 下面配置环境变量:
gedit ~/.bashrc
在最下面添加:
JAVA_HOME=/usr/lib/jvm/java/jdk1.6.0_45
PATH=${JAVA_HOME}/bin:$PATH
CLASSPATH=${JAVA_HOME}/lib:$CLASSPATH
保存后执行:
source~/.bashrc
然后运行:
java -version
输出:
java version"1.6.0_45"Java(TM) SE Runtime Environment (build1.6.0_45-b06)Java HotSpot(TM)64-Bit Server VM (build20.45-b01, mixed mode)
安装成功。
安装依赖包: 按照官方文档执行:
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
报错:
g++-multilib : Depends: gcc-multilib (>=4:4.8.2-1ubuntu6) but it is not going to be installed
是安装包依赖问题,用如下分别安装方式解决:
sudo apt-get install gcc
sudo apt-get install g++-multilib
sudo apt-get install git gnupg flex bison gperf build-essential zip curl libc6-dev libncurses5-dev:i386 libreadline6-dev:i386 g++-multilib mingw32 tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 dpkg-dev
sudo apt-get install lzop
sudo apt-get install keychain
分别安装后,再执官方文档的命令,看看是否有遗漏:
sudo apt-get install bison g++-multilib git gperf libxml2-utils make python-networkx zlib1g-dev:i386 zip
此时应该能够顺利安装完成。 官方文档还有很多其他配置,可以参考着配置,我没有再去配置其他。
下载源码: 这一步完全按照官方文档即可。
开始编译: 遇到make版本过高问题:
You are using version4.0of make. Android can only be built by versions3.81and3.82.
没办法,只能降级回来了,先remove掉4.0的make:
sudo apt-get remove make
从[这里]去下载3.81的make安装包,我下载是i386的deb包。 下载后执行命令安装:
sudo dpkg -i make*.deb
最后执行:
make -j16
时,报如下错:
androidsourceError: open CFI at the end of file; missing .cfi_endproc directive
改为执行:
make -j4
经过漫长的等待后,终于编译成功:
Creating filesystem with parameters: Size:576716800Block size:4096Blocks per group:32768Inodes per group:7040Inode size:256Journal blocks:2200Label: Blocks:140800Block groups:5Reserved block group size:39Created filesystem with1277/35200inodes and82233/140800blocks+'['0-ne0']'Install system fs image: out/target/product/generic/system.imgout/target/product/generic/system.img+ maxsize=588791808blocksize=2112total=576716800reserve=5947392
运行编译结果: 在编译的时候,默认输出在out目录下,编译出来的几个重要img文件如下:
$ out/target/product/generic/
total 575144
drwxrwxr-x10 ubt ubt 4096 Jul1422:19./
drwxrwxr-x3 ubt ubt 4096 Jul1419:33../
-rw-rw-r--1 ubt ubt 7Jul1419:38android-info.txt
drwxrwxr-x2 ubt ubt 4096 Jul1420:46cache/
-rw-r--r--1 ubt ubt 69206016 Jul1420:46cache.img //cache
-rw-rw-r--1 ubt ubt 40349 Jul1419:33clean_steps.mk
drwxrwxr-x4 ubt ubt 4096 Jul1421:28data/
drwxrwxr-x3 ubt ubt 4096 Jul1420:51dex_bootjars/
drwxrwxr-x2 ubt ubt 4096 Jul1422:18fake_packages/
-rw-rw-r--1 ubt ubt 59052 Jul1422:19installed-files.txt
drwxrwxr-x14 ubt ubt 4096 Jul1422:19obj/
-rw-rw-r--1 ubt ubt 671 Jul1419:33previous_build_config.mk
-rw-rw-r--1 ubt ubt 322856 Jul1421:23ramdisk.img //ramdisk
drwxrwxr-x8 ubt ubt 4096 Jul1421:23root/
drwxrwxr-x5 ubt ubt 4096 Jul1421:25symbols/
drwxrwxr-x13 ubt ubt 4096 Jul1421:42system/
-rw-r--r--1ubt ubt 576716800 Jul1422:19system.img //system
-rw-r--r--1ubt ubt 209715200 Jul1421:39userdata.img //userdata
编译结果中也包含了模拟器的执行脚本:
$ ~/AOSP/android-4.4.4_r2/out/host/linux-x86/bin/emulator