编译环境
AOSP
源码只能在Linux
或macOS
操作系统中编译,Android2.3
及更高版本只支持64位
环境。这里学习在Ubuntu 12.04LTS
操作系统中搭建编译环境。JDK
进入下载页面,勾选
Accept License Agreement
单选框,选择Linux
版本安装包,点击下载,下载页面重定向到Oracle
登录页面,注册新账户或使用已有的账户登录后即可下载JDK6
安装包。
下载完成后,安装:
$ chmod a+x jdk-6u45-linux-x64.bin
$ ./jdk-6u45-linux-x64.bin
# 如果/usr/lib/jvm目录不存在,创建目录
$ sudo mkdir -p /usr/lib/jvm
$ sudo mv jdk1.6.0_45 /usr/lib/jvm/java-6-oracle
$ sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-6-oracle/bin/java 1
$ sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-6-oracle/bin/javac 1
选择默认
java
版本:$ sudo update-alternatives --set java /usr/lib/jvm/java-6-oracle/bin/java
update-alternatives: using /usr/lib/jvm/java-6-oracle/bin/java to provide /usr/bin/java (java) in manual mode.
$ sudo update-alternatives --set javac /usr/lib/jvm/java-6-oracle/bin/javac
update-alternatives: using /usr/lib/jvm/java-6-oracle/bin/javac to provide /usr/bin/javac (javac) in manual mode.
添加 PPA
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
安装JDK6
$ sudo apt-get install oracle-java6-installer
设置默认JDK
$ sudo update-alternatives --config java
$ sudo update-alternatives --config javac
gcc4.4、g++4.4
Ubuntu12.04LTS
自带的gcc
版本为4.6.3
,需要安装4.4
版本的gcc
、g++
:$ sudo apt-get install gcc-4.4 g++-4.4 gcc-4.4-multilib g++-4.4-multilib
切换默认版本:
$ sudo update-alternatives --remove-all gcc
$ sudo update-alternatives --remove-all g++
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 20
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.4 20
$ gcc --version
gcc (Ubuntu/Linaro 4.4.7-1ubuntu2) 4.4.7
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ g++ --version
g++ (Ubuntu/Linaro 4.4.7-1ubuntu2) 4.4.7
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
安装其他依赖
$ 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
其中,
libgl1-mesa-glx:i386
在我本地环境中安装提示:The following packages have unmet dependencies:
libgl1-mesa-glx:i386 : Depends: libglapi-mesa:i386 (= 8.0.4-0ubuntu0.7)
Recommends: libgl1-mesa-dri:i386 (>= 7.2)
E: Unable to correct problems, you have held broken packages.
从列表中移除,安装其他包,目前在我本地没发现问题,可以正常编译使用。