Android源码4.4.4_r1下载和编译

系统:ubuntu 16.04.2 TLS

1.源码下载:

sudo apt-get install curl
curl https://storage.googleapis.com/git-repo-downloads/repo > repo
chmod a+x repo

mkdir srcAndroid
cd srcAndroid
git config --global user.name "xunbu7"
git config --global user.email "xunbu7@gmail.com"
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-4.4.4_r1
repo sync

选择目标版本源码,参考编译版本标签对照表:

https://source.android.com/source/build-numbers

2.驱动下载:

 https://developers.google.com/android/drivers

将下载下来的3个压缩包加压到源码目录,分别执行3个sh文件,输入“I ACCEPT”。可以看到源码目录多了一个vendor目录。删除sh文件即可。

3.环境配置

3.1 jdk环境

4.4.4_r1需要jdk6环境,而标准库不支持旧版本,所以下载方式如下:

Open the terminal and execute below commands one by one. It will install JDk as well as JRE. No need to configure anything. It will take care of everything.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

sudo apt-get install oracle-java6-installer //JDK 6 along with JRE
sudo apt-get install oracle-java7-installer //OR FOR JDK 7

有时候不知道java安装在哪里了,通过whereis java命令不能知道java真实的安装路径,可以通过update-alternatives --config java命令查看

bean@ubuntu :~$ update-alternatives --config java
There is only one alternative in link group java: /usr/lib/jvm/java-7-oracle/jre/bin/java
Nothing to configure.

或者官网下载到本地后

seven@ThinkPad:~/Downloads$ chmod a+x jdk-6u45-linux-x64.bin
seven@ThinkPad:~/Downloads$ ./jdk-6u45-linux-x64.bin
移动到自定义目录:
seven@ThinkPad:~/Documents/Android$ mv -f ~/Downloads/jdk1.6.0_45/ .
seven@ThinkPad:~/Documents/Android/jdk1.6.0_45$ pwd
/home/seven/Documents/Android/jdk1.6.0_45

修改配置文件:

seven@ThinkPad:~$ vim .bashrc
内容:
export JAVA_HOME=/home/seven/Documents/Android/jdk1.6.0_45
export JRE_HOME=${JAVA_HOME}/jre
export PATH=$PATH:${JAVA_HOME}/bin
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib

seven@ThinkPad:~$ source .bashrc
seven@ThinkPad:~$ javac -version
javac 1.6.0_45

3.2 安装make

ubuntu16.04自带的make版本过高,无法编译。因此需要将make降至3.82.

下载地址ftp://ftp.gnu.org/gnu/make/

下载后到Downloads下将文件拷到其他目录(home下即可),然后解压

tar -zxvf make3.8.2.tar.gz

解压后进入到make3.8.2的目录下

./configure
make
sudo make install

执行完后在/usr/local/bin中可得到新版本的make,复制到/usr/bin中即可

seven@ThinkPad:/usr/local/bin$ sudo mv make /usr/bin

注:make过程中可能会出现错误,不用理会,只要make install能够成功执行即可。

 3.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
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  unzip m4

4.编译

echo export USE_CCACHE=1 >> ~/.bashrc
prebuilts/misc/linux-x86/ccache/ccache -M 50G source build/envsetup.sh lunch aosp_hammerhead-userdebug //虚拟机中当时必须用sudo su (切换su,root下:否则上面5儿子配置会被虚拟机配置覆盖),后来用真实机不用也ok。 make –j8

5.刷机

源码编译完成后,我们开始将编译好的系统烧录进手机中。首先,先将我们的Nexus 5连接到电脑上,注意一定要打开USB调试,连接后手机可能会提示电脑要调试这台手机,允许即可。然后,我们令手机进入recovery模式,还是刚才的terminal(在源码根目录下),输入以下命令:

seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ ./adb reboot bootloader
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ sudo ./fastboot devices(用sudo,否则发现不了设备)
[sudo] password for seven: 
072ba3800ae5fd9c fastboot
seven@ThinkPad:~/srcAndroid/src4.4.4_r1/out/host/linux-x86/bin$ sudo ANDROID_PRODUCT_OUT=/home/seven/srcAndroid/src4.4.4_r1/out/target/product/hammerhead ./fastboot flashall -w(用sudo,否则发现不了设备)

或者也可以一个个img刷入:

0、重启进入刷机模式
adb reboot bootloader
1、依次刷入其他镜像文件:
fastboot flash recovery recovery.img
fastboot flash boot boot.img
fastboot flash system system.img
2、强烈建议双清(注意备份数据):
fastboot flash cache cache.img
fastboot flash userdata userdata.img
3、再次重启:
fastboot reboot
posted on 2017-05-25 20:34  寻步  阅读(2580)  评论(0编辑  收藏  举报