编译android4.4.4 for nexus4
参考https://source.android.com
1.配置开发环境 Initializing a Build Environment
编译Android4.4.4要求使用64bit系统.所以我在虚拟机上装了一个Ubuntu 14.04 64bit.
首先安装jdk,andorid官网提供的安装方法是是安装OpenJDK7,android4.4.4要求使用jdk1.6.所以我去oracle下载一个1.6版本的jdk
下载后执行:
sudo chmod a+x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
执行后会解压jdk到当前目录,接下来复制该文件夹到/usr/lib/jvm
sudo cp –rf jdk1.6.0_45/ /usr/lib/jvm
接下来配置JAVA环境变量,在/etc/profile中添加
JAVA_HOME=/usr/lib/jvm/jdk1.6.0_45
PATH=$JAVA_HOME/bin:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME
export PATH
export CLASSPATH
执行profile:
sudo source /etc/profile
再使用update alternatives切换JDK
kong@ubuntu:~$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java 1071 manual mode
* 3 /usr/lib/jvm/jdk1.6.0_45/bin/java 300 manual mode
Press enter to keep the current choice[*], or type selection number: 3
kong@ubuntu:~$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 auto mode
1 /usr/lib/jvm/java-6-openjdk-amd64/bin/javac 1061 manual mode
2 /usr/lib/jvm/java-7-openjdk-amd64/bin/javac 1071 manual mode
* 3 /usr/lib/jvm/jdk1.6.0_45/bin/javac 300 manual mode
Press enter to keep the current choice[*], or type selection number: 3
接下来安装各种库
sudo apt-get install bison g++-multilib git gperf libxml2-utils
完成之后接下来开始下载代码
首先在用户根目录新建一个文件夹bin
mkdir ~/bin
export PATH=~/bin:$PATH
下载repo
curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
chmod a+x ~/bin/repo
新建一个文件夹用于存放源代码
mkdir android4cd android4
初始化repo
kong@ubuntu:~/android4$ repo init -u https://android.googlesource.com/platform/manifest
接下来选择要下载的分支 这里选择android-4.4.4_r1 要下载其他版本可以在下面这个链接查询:
http://source.android.com/source/build-numbers.html#source-code-tags-and-builds
repo init -u https://android.googlesource.com/platform/manifest -b android-4.4.4_r1
接下来下载代码
repo sync
下载要很久.我下了两天…
下载完成之后可以在android4文件夹中看到所有文件:
kernel和vendor文件夹是后加的.后面再写.
接下来要添加vendor,vendor是不符合ASOP开源协议的厂家驱动部分,在
https://developers.google.com/android/nexus/drivers中可以找到:
将这三个文件下载后解压在android源代码根目录
此时按照android官方方法执行这三个shell脚本无法正常解压vendor文件,打开sh文件后可发现执行如下三条命令可以解压:
tail -n +276 extract-broadcom-mako.sh | tar zxvtail -n +276 extract-lge-mako.sh | tar zxvtail -n +315 extract-qcom-mako.sh | tar zxv
如果编译其他设备或者android版本,可以打开sh文件.在LICENSE后面找到本条命令.每个厂家LICENSE长度不同导致+后面参数不同.稍作修改即可.
完成以上步骤后即可开始编译源代码,注意,编译源代码建议设置4g 内存.(我的虚拟机设置2g ram时会卡在chrome的一个文件上…,据说可以添加swap.没试过)
在android根目录执行下面代码:
source build/envsetup.sh
lunch full_mako-userdebug
make –j4
编译完成后进入将手机进入fastboot,以下是各款nexus设备进入fastboot方法O(∩_∩)O~
再执行fastboot flashall –w
kong@ubuntu:~/android4$ fastboot flashall -w
< waiting for device >
--------------------------------------------
Bootloader Version...: MAKOZ30d
Baseband Version.....: M9615A-CEFWMAZM-2.0.1701.03
Serial Number........: xxxxxxxxxxxx--------------------------------------------
checking product...
OKAY [ 0.004s]
sending ‘boot‘ (6370 KB)...
OKAY [ 0.781s]
writing ‘boot‘...
OKAY [ 0.362s]
sending ‘recovery‘ (6918 KB)...
OKAY [ 0.869s]
writing ‘recovery‘...
OKAY [ 0.395s]
erasing ‘system‘...
OKAY [ 0.314s]
sending ‘system‘ (301507 KB)...
OKAY [ 36.709s]
writing ‘system‘...
OKAY [ 18.345s]
erasing ‘userdata‘...
OKAY [ 0.509s]
formatting ‘userdata‘ partition...
Creating filesystem with parameters:
Size: 6189744128
Block size: 4096
Blocks per group: 32768
Inodes per group: 8048
Inode size: 256
Journal blocks: 23612
Label:
Blocks: 1511168
Block groups: 47
Reserved block group size: 375
Created filesystem with 11/378256 inodes and 50366/1511168 blocks
sending ‘userdata‘ (98413 KB)...
writing ‘userdata‘...
OKAY [ 17.536s]
erasing ‘cache‘...
OKAY [ 0.046s]
formatting ‘cache‘ partition...
Creating filesystem with parameters:
Size: 587202560
Block size: 4096
Blocks per group: 32768
Inodes per group: 7168
Inode size: 256
Journal blocks: 2240
Label:
Blocks: 143360
Block groups: 5
Reserved block group size: 39
Created filesystem with 11/35840 inodes and 4616/143360 blocks
sending ‘cache‘ (10984 KB)...
writing ‘cache‘...
OKAY [ 1.963s]
rebooting...finished. total time: 77.850s
烧写完成就可以开机啦
编译过程中可能会遇见缺少某些文件,可以参考Jack大神的博客:
http://tianshuzhb.blog.163.com/blog/static/35137793201211872125183/
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。