为了实现在VM ubuntu 16.04 编译android 6.0源码,配置编译环境与源码的整体编译

1.前言:在Ubuntu编译android源码时,编译不通过最主要的原因是缺少所要依赖资源,所以在安装依赖时一定要看是否成功。

(1).编译条件:1.合适的Ubuntu系统:

 

2.配置Ubuntu编译条件
(1).备份sources.list,以防出错

sudo cp /etc/apt/sources.list /etc/apt/sources.list_back

(2).修改sources.list

sudo gedit /etc/apt/sources.list

前面追加

deb http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ quantal-backports main restricted universe multiverse

(3).安装依赖,确保每次要看是安装成功

sudo apt-get install -y git flex bison gperf build-essential libncurses5-dev:i386 
sudo apt-get install libx11-dev:i386 libreadline6-dev:i386 libgl1-mesa-dev g++-multilib 
sudo apt-get install tofrodos python-markdown libxml2-utils xsltproc zlib1g-dev:i386 
sudo apt-get install dpkg-dev libsdl1.2-dev libesd0-dev
sudo apt-get install git-core gnupg flex bison gperf build-essential  
sudo apt-get install zip curl zlib1g-dev gcc-multilib g++-multilib 
sudo apt-get install libc6-dev-i386 
sudo apt-get install lib32ncurses5-dev x11proto-core-dev libx11-dev 
sudo apt-get install lib32z-dev ccache
sudo apt-get install libgl1-mesa-dev libxml2-utils xsltproc unzip m4

(4).安装Android 6.0开始Android源码的编译需要的OpenJDK7


(可选)可以把sources.list中,接着步骤(2)后面的用下面替换掉,可以加快openjdk的下载速度,以及其他的一些常用的软件。

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

a.下载安装jdk

sudo add-apt-repository ppa:openjdk-r/ppa 
sudo apt-get update
sudo apt-get install openjdk-7-jdk

b.配置profile

sudo gedit /etc/profile

c.在末尾添加代码

export JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64
export JRE_HOME=${JAVA_HOME}/jre 
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib 
export PATH=${JAVA_HOME}/bin:$PATH

d.使profile生效

source /etc/profile

c.检查OpenJDK是否成功

java -version

android 源码编译 CMake_Ubuntu

3.合并后解压android6.0源码

a.把下载到window的8个文件复制到Ubuntu里面

android 源码编译 CMake_android 源码编译 CMake_02

b.合并8个文件

cat Android6_r1_*>Android6_r1.tgz

c.验证 Android6_r1.tgz 是否匹配 23858108e95095dc8d0292505a0d28e4

md5sum Android6_r1.tgz

android 源码编译 CMake_源码_03


注意:如果合并后的文件md5码不正确,要分别验证8个分卷,不匹配的卷要重新下载

以下是每个分卷的md5 :
a4129f5d2d6a8293ee3ee3ed4343f0fd Android6_r1_aa
e601f1239c0f60895cc6b9199b1cd7d1 Android6_r1_ab
af2d9e653a51072031ce40b62791c2de Android6_r1_ac
482866559a4d6a8533411e512436363c Android6_r1_ad
cef15f072f6d52243d9dea126c22f794 Android6_r1_ae
457979779748dae9f5f4f3c99db04826 Android6_r1_af
7ca217b1fd60a41c7ff9b7e294864fe3 Android6_r1_ag
5b468da830ef51fdd5f35d5d8ac72bd1 Android6_r1_ah
ba80f4acf5f61b1b82d3c1ba6ba702c1 Android6_r1_ai
4350d1bb74589ad03735279421dced92 Android6_r1_aj


d.解压

tar -zxvf Android6_r1.tgz

4.编译过程

(1).修改Android.common_build.mk文件

把ifneq ($(WITHOUT_HOST_CLANG),true) 改成 ifeq ($(WITHOUT_HOST_CLANG),false)
sudo gedit art/build/Android.common_build.mk

然后Ctrl+F 搜索后,替换两个地方

android 源码编译 CMake_Ubuntu_04


(2).在 .bashrc文件末尾添加:export USE_CCACHE = 1

echo export USE_CCACHE=1 >> ~/.bashrc

(3).接着导入继续编译的命令(详情vim build/envsetup.sh)

source build/envsetup.sh

(4).接着执行lunch,然后选择1,如下图

android 源码编译 CMake_ubuntu_05

(5).接着执行,数字8根据cpu核心数决定的,通常Ubuntu中的cpu*2+2,在cpu支持条件下,选择越大就编译速度越快

make -j8

接下来是等待漫长的过程,我编译了4个小时

android 源码编译 CMake_源码_06

5.开启模拟器

emulator

当开启模拟器,这两个种错误时
emulator: WARNING: system partition size adjusted to match image file (1536 MB > 200 MB)
emulator: WARNING: data partition size adjusted to match image file (550 MB > 200 MB)
执行下面,杀死进程后,给交换区分配2048M内存,让模拟器跑起来

ps aux | grep emulator
kill 进程号 -9
emulator -partition-size 2048

6.后语

(1).感谢这位博主资源依赖库:

(2).还有感谢这位博主的源码:

(3).使用vm 安装的ubuntu16.04请看:

(4).Android源码之路(三.配置mk文件):