心心念念的Android源码编译

源码下载

下载Repo工具

切换在工作目录中创建bin文件夹,并将该文件夹添加在PATH路径下, 并建议在~/.bashrc配置文件中添加export REPO_URL='https://mirrors.tuna.tsinghua.edu.cn/git/git-repo/'添加完成后参看下面的命令

mkdir ~/bin
PATH=~/bin:$PATH
cd ~/bin
curl https://mirrors.tuna.tsinghua.edu.cn/git/git-repo -o repo
chmod a+x ~/bin/repo

希望使用Google源的同志只需要将curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo替换上面的curl命令即可

repo是啥

简单来说repo就是git集合,当我们的项目过于庞大使用一个git管理显得力不从心的时候,此时最简单明了的解决方式当然是使用很多git来组织管理,repo就是在做这个事情,多提一句,repo使用python脚本语言

初始化repo并下载分支代码(耗时操作)

强烈建议各位想要自己尝试编译的大佬选择自己的设备下载源码, 不然这个时间就浪费了

Android版本 编译要求的Ubuntu最低版本 编译要求的JDK版本
Android 6.0 (Marshmallow) - AOSP master Ubuntu 14.04 OpenJDK 8
Android 5.x (Lollipop) - Android 6.0 (Marshmallow) Ubuntu 12.04 OpenJDK 7
Android 2.3.x (Gingerbread) - Android 4.4.x (KitKat) Ubuntu 12.04 Oracle JDK 6
Android 1.5 (Cupcake) - Android 2.3.x (Gingerbread) Ubuntu 10.04 Oracle JDK 5

Android 4.0.x (Ice Cream Sandwich) 及更低版本需要将make命令还原到较低版本,以避免出现编译错误。
Mac系统要求和更多可见https://source.android.com/source/requirements.html

mkdir WORKING_DIRECTORY
cd WORKING_DIRECTORY
repo init -u https://aosp.tuna.tsinghua.edu.cn/platform/manifest -b android-7.0.1-_r14
repo sync

等待...emmm, 建议去喝个茶, 陪女朋友逛个街, 睡个觉啥的...这个过程比较耗时尤其是使用Google源的哥们repo init -u https://android.googlesource.com/platform/manifest

由于容易最后的sync过程由于网络原因很容易失败, 因此小工具如下

#!/bin/sh
repo sync
while [ $? -ne 0 ]
do
repo sync
done

分支切换

查看当前分支

repo的版本管理信息存储在.repo路径下, 即查看当前分支

cd .repo/manifests
git branch -a

分支切换

  1. 切换前需要回退已有修改(如果大佬改了源码的话)
repo forall -c git reset --hard
  1. 回退完成后可以选择, 使用初始化命令切换版本
repo init -u git://mirrors.ustc.edu.cn/aosp/platform/manifest -b android-5.1.1

checkout命令切换

repo forall -c git checkout android-5.1.1_r1
  1. 然后执行同步即可, 可别忘了小工具
repo sync

执行完成后,如果是使用checkout切换, 还需要执行repo start android-5.1.1_r1 --all即可

  1. 免除切换网络的繁复
    Source Code Tags and Builds部分摘录如下
细分版本 分支 版本 支持的设备
OPR5.170623.007 android-8.0.0_r17 Oreo Nexus 6P
OPR4.170623.009 android-8.0.0_r16 Oreo Nexus 5X
OPR3.170623.008 android-8.0.0_r15 Oreo Pixel XL、Pixel
OPR1.170623.027 android-8.0.0_r13 Oreo Pixel XL、Pixel、Pixel C
OPR6.170623.021 android-8.0.0_r12 Oreo Nexus Player
OPR6.170623.019 android-8.0.0_r11 Oreo Nexus 6P
OPR4.170623.006 android-8.0.0_r10 Oreo Nexus 5X
OPR3.170623.007 android-8.0.0_r9 Oreo Pixel XL、Pixel
OPR1.170623.026 android-8.0.0_r7 Oreo Pixel XL、Pixel、Pixel C
OPR6.170623.013 android-8.0.0_r4 Oreo Nexus 5X、Nexus 6P
OPR6.170623.012 android-8.0.0_r3 Oreo Pixel XL、Pixel
OPR6.170623.011 android-8.0.0_r2 Oreo Pixel XL、Pixel
OPR6.170623.010 android-8.0.0_r1 Oreo Pixel C
NZH54D android-7.1.2_r33 Nougat Pixel XL、Pixel
NKG47S android-7.1.2_r32 Nougat Pixel XL、Pixel
NHG47Q android-7.1.2_r30 Nougat Pixel XL、Pixel
NJH47F android-7.1.2_r29 Nougat Pixel XL、Pixel
N2G48C android-7.1.2_r28 Nougat Nexus 5X、Nexus 6P、Nexus Player、Pixel C
NZH54B android-7.1.2_r27 Nougat Pixel XL、Pixel
NKG47M android-7.1.2_r25 Nougat Pixel XL、Pixel
NJH47D android-7.1.2_r24 Nougat Pixel XL、Pixel
NHG47O android-7.1.2_r23 Nougat Pixel XL、Pixel
N2G48B android-7.1.2_r19 Nougat Nexus 6P、Nexus Player、Pixel C
N2G47Z android-7.1.2_r18 Nougat Nexus 5X
NJH47B android-7.1.2_r17 Nougat Pixel XL、Pixel
NJH34C android-7.1.2_r16 Nougat Pixel XL、Pixel
NKG47L android-7.1.2_r15 Nougat Pixel XL、Pixel
NHG47N android-7.1.2_r14 Nougat Pixel XL、Pixel
N2G47X android-7.1.2_r13 Nougat Nexus Player
N2G47W android-7.1.2_r12 Nougat Nexus 5X、Nexus 6P、Pixel C
NHG47L android-7.1.2_r11 Nougat Pixel XL、Pixel
N2G47T android-7.1.2_r10 Nougat Pixel XL、Pixel
N2G47R android-7.1.2_r9 Nougat Nexus Player
N2G47O android-7.1.2_r8 Nougat Nexus 5X、Nexus 6P、Pixel XL、Pixel、Pixel C
NHG47K android-7.1.2_r6 Nougat Pixel XL、Pixel
N2G47J android-7.1.2_r5 Nougat Pixel XL、Pixel
N2G47H android-7.1.2_r4 Nougat Nexus 6P、Nexus Player
N2G47F android-7.1.2_r3 Nougat Nexus 5X
N2G47E android-7.1.2_r2 Nougat Pixel XL、Pixel
N2G47D android-7.1.2_r1 Nougat Pixel C
N9F27M android-7.1.1_r58 Nougat Nexus 9 (volantis)
NGI77B android-7.1.1_r57 Nougat Nexus 6
N6F27M android-7.1.1_r55 Nougat Nexus 6
N4F27P android-7.1.1_r54 Nougat Nexus 9 (volantisg)
N9F27L android-7.1.1_r53 Nougat Nexus 9
NGI55D android-7.1.1_r52 Nougat Nexus 6
N4F27O android-7.1.1_r51 Nougat Nexus 9 (volantisg)
N8I11B android-7.1.1_r50 Nougat Nexus 6
N9F27H android-7.1.1_r49 Nougat Nexus 9 (volantis)
N6F27I android-7.1.1_r48 Nougat Nexus 6
N4F27K android-7.1.1_r47 Nougat Nexus 9 (volantisg)
N9F27F android-7.1.1_r46 Nougat Nexus 9 (volantis)
N6F27H android-7.1.1_r45 Nougat Nexus 6
N4F27I android-7.1.1_r44 Nougat Nexus 9 (volantisg)
N9F27C android-7.1.1_r43 Nougat Nexus 9 (volantis)
N6F27E android-7.1.1_r42 Nougat Nexus 6
N4F27E android-7.1.1_r41 Nougat Nexus 9 (volantisg)
N6F27C android-7.1.1_r40 Nougat Nexus 6
N4F27B android-7.1.1_r39 Nougat Nexus 9 (volantis/volantisg)
N6F26Y android-7.1.1_r38 Nougat Nexus 6
NOF27D android-7.1.1_r35 Nougat Pixel XL、Pixel
N4F26X android-7.1.1_r33 Nougat Nexus 9 (volantis/volantisg)
N4F26U android-7.1.1_r31 Nougat Nexus 5X、Nexus 6P
N6F26U android-7.1.1_r28 Nougat Nexus 6
NUF26N android-7.1.1_r27 Nougat Nexus 6P
NOF27C android-7.1.1_r26 Nougat Pixel XL、Pixel
NOF27B android-7.1.1_r25 Nougat Pixel XL、Pixel
N4F26T android-7.1.1_r24 Nougat Nexus 5X、Nexus 6P、Nexus 9 (volantis/volantisg)、Pixel C
NMF27D android-7.1.1_r23 Nougat Nexus Player
NMF26X android-7.1.1_r22 Nougat Nexus Player
NOF26W android-7.1.1_r21 Nougat Pixel XL、Pixel
NOF26V android-7.1.1_r20 Nougat Pixel XL、Pixel
N6F26R android-7.1.1_r17 Nougat Nexus 6
NUF26K android-7.1.1_r16 Nougat Nexus 6P
N4F26Q android-7.1.1_r15 Nougat Nexus 9 (volantis/volantisg)
N4F26O android-7.1.1_r14 Nougat Nexus 5X、Nexus 6P、Pixel C
N6F26Q android-7.1.1_r13 Nougat Nexus 6
N4F26M android-7.1.1_r12 Nougat Nexus 9 (volantis)
N4F26J android-7.1.1_r11 Nougat Nexus 5X、Nexus 6P
N4F26I android-7.1.1_r10 Nougat Nexus 5X、Nexus 6P、Pixel C
NMF26V android-7.1.1_r9 Nougat Pixel XL、Pixel
NMF26U android-7.1.1_r8 Nougat Pixel XL、Pixel
NMF26R android-7.1.1_r7 Nougat Nexus Player
NMF26Q android-7.1.1_r6 Nougat Pixel XL、Pixel
NMF26O android-7.1.1_r4 Nougat Pixel XL、Pixel
NMF26J android-7.1.1_r3 Nougat Nexus Player
NMF26H android-7.1.1_r2 Nougat Pixel C
NMF26F android-7.1.1_r1 Nougat Nexus 5X、Nexus 6P、Nexus 9 (volantis/volantisg)
NDE63X android-7.1.0_r7 Nougat Pixel XL、Pixel
NDE63V android-7.1.0_r6 Nougat Pixel XL、Pixel
NDE63U android-7.1.0_r5 Nougat Pixel XL、Pixel
NDE63P android-7.1.0_r4 Nougat Pixel XL、Pixel
NDE63L android-7.1.0_r2 Nougat Pixel XL、Pixel
NDE63H android-7.1.0_r1 Nougat Pixel XL、Pixel
NBD92G android-7.0.0_r33 Nougat Nexus 6
NBD92F android-7.0.0_r32 Nougat Nexus 6
NBD92E android-7.0.0_r31 Nougat Nexus 6
NBD92D android-7.0.0_r30 Nougat Nexus 6
NBD91Z android-7.0.0_r29 Nougat Nexus 6
NBD91Y android-7.0.0_r28 Nougat Nexus 6
NBD91X android-7.0.0_r27 Nougat Nexus 6
NBD91U android-7.0.0_r24 Nougat Nexus 6
N5D91L android-7.0.0_r21 Nougat Nexus 5X
NBD91P android-7.0.0_r19 Nougat Nexus 6
NRD91K android-7.0.0_r17 Nougat Nexus 6P
NRD91N android-7.0.0_r15 Nougat Nexus 5X、Pixel C、Nexus Player、Nexus 9 (volantis/volantisg)
NBD90Z android-7.0.0_r14 Nougat Nexus 6
NBD90X android-7.0.0_r13 Nougat Nexus 6P
NBD90W android-7.0.0_r12 Nougat Nexus 5X
NRD91D android-7.0.0_r7 Nougat Pixel C、Nexus Player、Nexus 9 (WLAN)
NRD90U android-7.0.0_r6 Nougat Nexus 6P
NRD90T android-7.0.0_r5 Nougat Nexus 6P
NRD90S android-7.0.0_r4 Nougat Nexus 5X
NRD90R android-7.0.0_r3 Nougat Nexus 5X、Nexus 9 (volantis)、Nexus Player、Pixel C
NRD90M android-7.0.0_r1 Nougat Nexus 5X、Nexus 9 (volantis)、Nexus Player、Pixel C
MOB31Z android-6.0.1_r80 Marshmallow
MOB31T android-6.0.1_r79 Marshmallow Nexus 6
MOB31S android-6.0.1_r78 Marshmallow Nexus 6
M4B30Z android-6.0.1_r77 Marshmallow Nexus 5
MOB31K android-6.0.1_r74 Marshmallow Nexus 6
MMB31C android-6.0.1_r73 Marshmallow Nexus 6
M4B30X android-6.0.1_r72 Marshmallow Nexus 5
MOB31H android-6.0.1_r70 Marshmallow Nexus 6
MMB30Y android-6.0.1_r69 Marshmallow Nexus 6
MTC20K android-6.0.1_r67 Marshmallow Nexus 5X
MOB31E android-6.0.1_r66 Marshmallow Nexus 5、Nexus 6、Nexus 9 (volantis)
MMB30W android-6.0.1_r65 Marshmallow Nexus 6
MXC89L android-6.0.1_r63 Marshmallow Pixel C
MTC20F android-6.0.1_r62 Marshmallow Nexus 5X、Nexus 6P
MOB30Y android-6.0.1_r60 Marshmallow Nexus 5
MOB30X android-6.0.1_r59 Marshmallow Nexus 7 (flo/deb)
MOB30W android-6.0.1_r58 Marshmallow Nexus 6、Nexus 9 (volantis/volantisg)、Nexus Player
MMB30S android-6.0.1_r57 Marshmallow Nexus 7 (deb)
MMB30R android-6.0.1_r56 Marshmallow Nexus 6
MXC89K android-6.0.1_r55 Marshmallow Pixel C
MTC19Z android-6.0.1_r54 Marshmallow Nexus 5X
MTC19X android-6.0.1_r53 Marshmallow Nexus 6P
MOB30P android-6.0.1_r50 Marshmallow Nexus 5、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)、Nexus Player
MOB30O android-6.0.1_r49 Marshmallow Nexus 6
MMB30M android-6.0.1_r48 Marshmallow Nexus 7 (deb)
MMB30K android-6.0.1_r47 Marshmallow Nexus 6
MOB30M android-6.0.1_r46 Marshmallow Nexus 5、Nexus 6、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)、Nexus Player
MTC19V android-6.0.1_r45 Marshmallow Nexus 5X、Nexus 6P
MOB30J android-6.0.1_r43 Marshmallow Nexus 7 (flo/deb)
MOB30I android-6.0.1_r42 Marshmallow Nexus 6
MOB30H android-6.0.1_r41 Marshmallow Nexus 5
MOB30G android-6.0.1_r40 Marshmallow Nexus 9 (volantis/volantisg)、Nexus Player
MXC89H android-6.0.1_r33 Marshmallow Pixel C
MXC89F android-6.0.1_r32 Marshmallow Pixel C
MMB30J android-6.0.1_r28 Marshmallow Nexus 6、Nexus 7 (deb)
MTC19T android-6.0.1_r25 Marshmallow Nexus 5X、Nexus 6P
M5C14J android-6.0.1_r31 Marshmallow Pixel C
MOB30D android-6.0.1_r30 Marshmallow Nexus 5、Nexus 6、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)、Nexus Player
MHC19Q android-6.0.1_r24 Marshmallow Nexus 5X、Nexus 6P
MHC19J android-6.0.1_r22 Marshmallow Nexus 5X
MHC19I android-6.0.1_r21 Marshmallow Nexus 6P
MMB29X android-6.0.1_r20 Marshmallow Nexus 5、Nexus 6、Nexus 7 (deb)、Nexus 9 (volantisg)
MXC14G android-6.0.1_r18 Marshmallow Pixel C
MMB29V android-6.0.1_r17 Marshmallow Nexus 5、Nexus 5X、Nexus 6、Nexus 6P、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)
MXB48T android-6.0.1_r16 Marshmallow Pixel C
MMB29U android-6.0.1_r13 Marshmallow Nexus Player
MMB29R android-6.0.1_r12 Marshmallow Nexus 9 (volantis/volantisg)
MMB29Q android-6.0.1_r11 Marshmallow Nexus 5、Nexus 5X、Nexus 6、Nexus 6P、Nexus 7 (flo/deb)
MMB29T android-6.0.1_r10 Marshmallow Nexus Player
MMB29S android-6.0.1_r9 Marshmallow Nexus 5、Nexus 6、Nexus 9 (volantis/volantisg)
MMB29P android-6.0.1_r8 Marshmallow Nexus 5X、Nexus 6P
MMB29O android-6.0.1_r7 Marshmallow Nexus 7 (flo/deb)
MXB48K android-6.0.1_r5 Marshmallow Pixel C
MXB48J android-6.0.1_r4 Marshmallow Pixel C
MMB29M android-6.0.1_r3 Marshmallow Nexus 6P、Nexus Player
MMB29K android-6.0.1_r1 Marshmallow Nexus 5、Nexus 5X、Nexus 6、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)
MMB29N android-6.0.0_r41 Marshmallow Nexus 6P
MDB08M android-6.0.0_r26 Marshmallow Nexus 5X、Nexus 6P
MDB08L android-6.0.0_r25 Marshmallow Nexus 5X、Nexus 6P
MDB08K android-6.0.0_r24 Marshmallow Nexus 6P
MDB08I android-6.0.0_r23 Marshmallow Nexus 5X
MDA89E android-6.0.0_r12 Marshmallow Nexus 5X
MDA89D android-6.0.0_r11 Marshmallow Nexus 6P
MRA59B android-6.0.0_r7 Marshmallow Nexus 7 (deb)
MRA58X android-6.0.0_r6 Marshmallow Nexus 6
MRA58V android-6.0.0_r5 Marshmallow Nexus 7 (flo/deb)
MRA58U android-6.0.0_r4 Marshmallow Nexus 7 (flo)
MRA58N android-6.0.0_r2 Marshmallow Nexus 5、Nexus 6、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)、Nexus Player
MRA58K android-6.0.0_r1 Marshmallow Nexus 5、Nexus 6、Nexus 7 (flo/deb)、Nexus 9 (volantis/volantisg)、Nexus Player
LMY49M android-5.1.1_r38 Lollipop Nexus 10
LMY49J android-5.1.1_r37 Lollipop Nexus 10
LMY49I android-5.1.1_r36 Lollipop Nexus 10
LMY49H android-5.1.1_r35 Lollipop Nexus 10
LMY49G android-5.1.1_r34 Lollipop Nexus 10
LMY49F android-5.1.1_r33 Lollipop Nexus 9 (volantisg)、Nexus 10
LMY48Z android-5.1.1_r30 Lollipop Nexus 6、Nexus 7 (deb)、Nexus 9 (volantisg)、Nexus 10
LYZ28N android-5.1.1_r28 Lollipop Nexus 6(仅面向 T-Mobile)
LMY48Y android-5.1.1_r26 Lollipop Nexus 6
LMY48X android-5.1.1_r25 Lollipop Nexus 6、Nexus 7 (deb)、Nexus 9 (volantisg)、Nexus 10
LMY48W android-5.1.1_r24 Lollipop Nexus 6
LVY48H android-5.1.1_r23 Lollipop Nexus 6(仅面向 Project Fi)
LYZ28M android-5.1.1_r22 Lollipop Nexus 6(仅面向 T-Mobile)
LMY48U android-5.1.1_r20 Lollipop Nexus 7 (deb)
LMY48T android-5.1.1_r19 Lollipop Nexus 4、Nexus 6、Nexus 9 (volantis/volantisg)、Nexus 10
LVY48F android-5.1.1_r18 Lollipop Nexus 6(仅面向 Project Fi)
LYZ28K android-5.1.1_r17 Lollipop Nexus 6(仅面向 T-Mobile)
LMY48P android-5.1.1_r16 Lollipop Nexus 7 (deb)
LMY48N android-5.1.1_r15 Lollipop Nexus Player
LMY48M android-5.1.1_r14 Lollipop Nexus 4、Nexus 5、Nexus 6、Nexus 7 (flo)、Nexus 9 (volantis/volantisg)、Nexus 10
LVY48E android-5.1.1_r13 Lollipop Nexus 6(仅面向 Project Fi)
LYZ28J android-5.1.1_r12 Lollipop Nexus 6(仅面向 T-Mobile)
LMY48J android-5.1.1_r10 Lollipop Nexus Player
LMY48I android-5.1.1_r9 Lollipop Nexus 4、Nexus 5、Nexus 6、Nexus 7 (flo)、Nexus 9 (volantis/volantisg)、Nexus 10
LVY48C android-5.1.1_r8 Lollipop Nexus 6(仅面向 Project Fi)
LMY48G android-5.1.1_r6 Lollipop Nexus 7 (flo)
LYZ28E android-5.1.1_r5 Lollipop Nexus 6(仅面向 T-Mobile)
LMY47Z android-5.1.1_r4 Lollipop Nexus 6(面向除 T-Mobile(美国)之外的所有运营商)
LMY48B android-5.1.1_r3 Lollipop Nexus 5
LMY47X android-5.1.1_r2 Lollipop Nexus 9 (volantis)
LMY47V android-5.1.1_r1 Lollipop Nexus 7 (flo/grouper)、Nexus 10、Nexus Player
LMY47O android-5.1.0_r5 Lollipop Nexus 4、Nexus 7 (flo/deb)
LMY47M android-5.1.0_r4 Lollipop Nexus 6(仅面向 T-Mobile)
LMY47I android-5.1.0_r3 Lollipop Nexus 5、Nexus 6
LMY47E android-5.1.0_r2 Lollipop Nexus 6
LMY47D android-5.1.0_r1 Lollipop Nexus 5、Nexus 6、Nexus 7 (grouper/tilapia)、Nexus 10、Nexus Player
LRX22L android-5.0.2_r3 Lollipop Nexus 9 (volantis/volantisg)
LRX22G android-5.0.2_r1 Lollipop Nexus 7 (flo/deb/grouper/tilapia)、Nexus 10
LRX22C android-5.0.1_r1 Lollipop Nexus 4、Nexus 5、Nexus 6 (shamu)、Nexus 7 (flo)、Nexus 9 (volantis/volantisg)、Nexus 10
LRX21V android-5.0.0_r7.0.1 Lollipop Nexus Player (fugu)
LRX21T android-5.0.0_r6.0.1 Lollipop Nexus 4
LRX21R android-5.0.0_r5.1.0.1 Lollipop Nexus 9 (volantis)
LRX21Q android-5.0.0_r5.0.1 Lollipop Nexus 9 (volantis)
LRX21P android-5.0.0_r4.0.1 Lollipop Nexus 7 (flo/grouper)、Nexus 10
LRX21O android-5.0.0_r3.0.1 Lollipop Nexus 5 (hammerhead)、Nexus 6 (shamu)
LRX21M android-5.0.0_r2.0.1 Lollipop Nexus Player (fugu)
LRX21L android-5.0.0_r1.0.1 Lollipop Nexus 9 (volantis)
KTU84Q android-4.4.4_r2 KitKat Nexus 5 (hammerhead)(仅面向新西兰的 2Degrees、澳大利亚的 Telstra 和印度)
KTU84P android-4.4.4_r1 KitKat Nexus 5、Nexus 7 (flo/deb/grouper/tilapia)、Nexus 4、Nexus 10
KTU84M android-4.4.3_r1.1 KitKat Nexus 5 (hammerhead)
KTU84L android-4.4.3_r1 KitKat Nexus 7 (flo/deb/grouper/tilapia)、Nexus 4、Nexus 10
KVT49L android-4.4.2_r2 KitKat Nexus 7 (deb Verizon)
KOT49H android-4.4.2_r1 KitKat Nexus 5、Nexus 7 (flo/deb/grouper/tilapia)、Nexus 4、Nexus 10
KOT49E android-4.4.1_r1 KitKat Nexus 5、Nexus 7 (flo/deb/grouper/tilapia)、Nexus 4、Nexus 10
KRT16S android-4.4_r1.2 KitKat Nexus 7 (flo/deb/grouper/tilapia)、Nexus 4、Nexus 10
KRT16M android-4.4_r1 KitKat Nexus 5 (hammerhead)
JLS36I android-4.3.1_r1 Jelly Bean Nexus 7 (deb)
JLS36C android-4.3_r3 Jelly Bean Nexus 7 (deb)
JSS15R android-4.3_r2.3 Jelly Bean Nexus 7 (flo)
JSS15Q android-4.3_r2.2 Jelly Bean Nexus 7 (flo)
JSS15J android-4.3_r2.1 Jelly Bean Nexus 7 (flo/deb)
JSR78D android-4.3_r2 Jelly Bean Nexus 7 (deb)
JWR66Y android-4.3_r1.1 Jelly Bean Galaxy Nexus、Nexus 7 (grouper/tilapia)、Nexus 4、Nexus 10
JWR66V android-4.3_r1 Jelly Bean Galaxy Nexus、Nexus 7 (grouper/tilapia)、Nexus 4、Nexus 10
JWR66N android-4.3_r0.9.1 Jelly Bean Galaxy Nexus、Nexus 7 (grouper/tilapia/flo)、Nexus 4、Nexus 10
JWR66L android-4.3_r0.9 Jelly Bean Nexus 7
JDQ39E android-4.2.2_r1.2 Jelly Bean Nexus 4
JDQ39B android-4.2.2_r1.1 Jelly Bean Nexus 7
JDQ39 android-4.2.2_r1 Jelly Bean Galaxy Nexus、Nexus 7、Nexus 4、Nexus 10
JOP40G android-4.2.1_r1.2 Jelly Bean Nexus 4
JOP40F android-4.2.1_r1.1 Jelly Bean Nexus 10
JOP40D android-4.2.1_r1 Jelly Bean Galaxy Nexus、Nexus 7、Nexus 4、Nexus 10
JOP40C android-4.2_r1 Jelly Bean Galaxy Nexus、Nexus 7、Nexus 4、Nexus 10
JZO54M android-4.1.2_r2.1 Jelly Bean
JZO54L android-4.1.2_r2 Jelly Bean
JZO54K android-4.1.2_r1 Jelly Bean Nexus S、Galaxy Nexus、Nexus 7
JRO03S android-4.1.1_r6.1 Jelly Bean Nexus 7
JRO03R android-4.1.1_r6 Jelly Bean Nexus S 4G
JRO03O android-4.1.1_r5 Jelly Bean Galaxy Nexus
JRO03L android-4.1.1_r4 Jelly Bean Nexus S
JRO03H android-4.1.1_r3 Jelly Bean
JRO03E android-4.1.1_r2 Jelly Bean Nexus S
JRO03D android-4.1.1_r1.1 Jelly Bean Nexus 7
JRO03C android-4.1.1_r1 Jelly Bean Galaxy Nexus
IMM76L android-4.0.4_r2.1 Ice Cream Sandwich
IMM76K android-4.0.4_r2 Ice Cream Sandwich Galaxy Nexus
IMM76I android-4.0.4_r1.2 Ice Cream Sandwich Galaxy Nexus
IMM76D android-4.0.4_r1.1 Ice Cream Sandwich Nexus S、Nexus S 4G、Galaxy Nexus
IMM76 android-4.0.4_r1 Ice Cream Sandwich
IML77 android-4.0.3_r1.1 Ice Cream Sandwich
IML74K android-4.0.3_r1 Ice Cream Sandwich Nexus S
ICL53F android-4.0.2_r1 Ice Cream Sandwich Galaxy Nexus
ITL41F android-4.0.1_r1.2 Ice Cream Sandwich Galaxy Nexus
ITL41D android-4.0.1_r1.1 Ice Cream Sandwich Galaxy Nexus
ITL41D android-4.0.1_r1 Ice Cream Sandwich Galaxy Nexus
GWK74 android-2.3.7_r1 Gingerbread Nexus S 4G
GRK39F android-2.3.6_r1 Gingerbread Nexus One、Nexus S
GRK39C android-2.3.6_r0.9 Gingerbread Nexus S
GRJ90 android-2.3.5_r1 Gingerbread Nexus S 4G
GRJ22 android-2.3.4_r1 Gingerbread Nexus One、Nexus S、Nexus S 4G
GRJ06D android-2.3.4_r0.9 Gingerbread Nexus S 4G
GRI54 android-2.3.3_r1.1 Gingerbread Nexus S
GRI40 android-2.3.3_r1 Gingerbread Nexus One、Nexus S
GRH78C android-2.3.2_r1 Gingerbread Nexus S
GRH78 android-2.3.1_r1 Gingerbread Nexus S
GRH55 android-2.3_r1 Gingerbread 使用 Gingerbread 最早期版本的设备、Nexus S
FRK76C android-2.2.3_r2 Froyo
FRK76 android-2.2.3_r1 Froyo
FRG83G android-2.2.2_r1 Froyo Nexus One
FRG83D android-2.2.1_r2 Froyo Nexus One
FRG83 android-2.2.1_r1 Froyo Nexus One
FRG22D android-2.2_r1.3 Froyo
FRG01B android-2.2_r1.2 Froyo
FRF91 android-2.2_r1.1 Froyo Nexus One
FRF85B android-2.2_r1 Froyo Nexus One
EPF21B android-2.1_r2.1p2 Eclair
ESE81 android-2.1_r2.1s Eclair
EPE54B android-2.1_r2.1p Eclair Nexus One
ERE27 android-2.1_r2 Eclair Nexus One
ERD79 android-2.1_r1 Eclair Nexus One
ESD56 android-2.0.1_r1 Eclair
ESD20 android-2.0_r1 Eclair
DMD64 android-1.6_r1.5 Donut
DRD20 android-1.6_r1.4
DRD08 android-1.6_r1.3
DRC92 android-1.6_r1.2

表格生成小工具: http://www.tablesgenerator.com/markdown_tables

替换当前已有的源码的远程仓库

需要修改两个文件

  1. .repo/manifest.xml文件remote name="aosp"标签下的fetch路径
<manifest>

   <remote  name="aosp"
-           fetch="https://android.googlesource.com"
+           fetch="https://aosp.tuna.tsinghua.edu.cn"
            review="android-review.googlesource.com" />

   <remote  name="github"
  1. .repo/manifests.git/config文件中的url
- url = https://android.googlesource.com/platform/manifest
+ url = https://aosp.tuna.tsinghua.edu.cn/platform/manifest

编译源码

编译环境配置

官方配置流程https://source.android.com/source/initializing.html
注: Android 4.0的代码只能使用jdk版本JDK_SE1.6, Make版本3.81,并强烈推荐使用Linux系统编译而不是Mac或Windows, 本文使用Ubuntu 18.04
图省事的大佬,请看下面一步到位的呵护

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

make命令安装

下载需要的make版本源码: ftp://ftp.gnu.org/gnu/make/

tar -zxvf make-3.81.tar.gz
cd make-3.81/
./configure
make

执行到这里的时候如果遇到错误了,比如像这个亚子的

/make-3.81/glob/glob.c:575: undefined reference to `__alloca'
glob/libglob.a(glob.o):/home/ziv/Desktop/make-3.81/glob/glob.c:726: more undefined references to `__alloca' follow

不要慌, 找到make-3.81/glob/glob.c这个文件, 找到这句话#if !defined __alloca && !defined __GNU_LIBRARY__, 去掉defined __GNU_LIBRARY__前的感叹号

if !defined __alloca && defined __GNU_LIBRARY__

保存退出,重新执行make

make
sudo make install

当当当当, 安装成功...

openjdk安装

sudo add-apt-repository ppa:openjdk-r/ppa 
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternative --config java

安装完成, 切换完java版本后一定要记得重新开一个终端,执行一下java -version看看是不是切换成功了

正式编译(耗时操作)

source build/envsetup.sh
lunch aosp_arm-eng
make

是的你没有看错,只要你配好了环境,编译就是这么简单,
需要注意的是lunch命令不带参数输入后,可以选择你想要编译的编译目标格式
所有编译目标都采用 BUILD-BUILDTYPE 形式,其中 BUILD 是表示特定功能组合的代号。BUILDTYPE 是以下类型之一

编译类型 使用情况
user 权限受限;适用于生产环境
userdebug 与“user”类似,但具有 root 权限和调试功能;是进行调试时的首选编译类型
eng 具有额外调试工具的开发配置

沧海桑田, 历经无数个岁月, 终于成功了...

### make completed successfully (01:18:45(hh:mm:ss)) ###

模拟器运行

source build/envsetup.sh
lunch(选择刚才你设置的目标版本,比如这里了我选择的是2)
emulator

模拟器相关(选修)

使用的Linux内核文件 Linux Kernel : kernel-qemu /source/prebuilds/qemu-kernel/arm/kernel-qemu
Android系统镜像文件: system.img, userdate.img, ramdisk.img
source/out/target/product/generic64位source/out/target/product/generic64

模块编译

执行source build/envsetup.sh之后

croot: Changes directory to the top of the tree.
m: Makes from the top of the tree.
mm: Builds all of the modules in the current directory.
mmm: Builds all of the modules in the supplied directories.
cgrep: Greps on all local C/C++ files.
jgrep: Greps on all local Java files.
resgrep: Greps on all local res/*.xml files.
godir: Go to the directory containing a file.

mmm: 编译指定目录
make snod: 重新打包系统镜像

系统自带的apk文件out/target/product/generic/system/apk
可执行工具模块:out/target/product/generic/system/bin
动态链接库:out/target/product/generic/system/lib
硬件抽象层文件:out/targer/product/generic/system/lib/hw

SDK编译

执行make sdk即可,但这个除非定制开发工具,一般不会执行

错误锦集

  1. java版本
You are attemping to build with the incorrect version.

解决方法
参看上文安装对应required的Java版本

  1. bison缺失
prebuilts/misc/linux-x86/bison/bison: m4 subprocess failed: No such file or directory

解决方法
sudo apt-get install flex bison

  1. flex错误
Assertion `cnt < (sizeof (_nl_value_type_LC_TIME) / sizeof (_nl_value_type_LC_TIME[0]))' failed

解决方法
export LC_ALL=C 或安装最新的flex:sudo apt-get install flex

  1. Out of memory error
Out of memory error (version 1.2-rc4 'Carnac' (298900 f95d7bdecfceb327f9d201a1348397ed8a843843 by android-jack-team@google.com)).
GC overhead limit exceeded.
Try increasing heap size with java option '-Xmx<size>'.
Warning: This may have produced partial or corrupted output.
ninja: build stopped: subcommand failed.
make: *** [ninja_wrapper] Error 1

编译AOSP主线代码时,常常会因为JVM heap size太小而导致该错误.
解决方法一
在编译命令之前,修改prebuilts/sdk/tools/jack-admin文件,找到文件中的这一行:

JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -cp $LAUNCHER_JAR $LAUNCHER_NAME"

然后在该行添加-Xmx4096m,即:

JACK_SERVER_COMMAND="java -XX:MaxJavaStackTraceDepth=-1 -Djava.io.tmpdir=$TMPDIR $JACK_SERVER_VM_ARGUMENTS -Xmx4096m -cp $LAUNCHER_JAR $LAUNCHER_NAME"

解决方法二

export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server

修改结束文件或执行完方法二之后,执行make继续编译
如果执行jack-admin kill-server提示命令不存在时,亲,这边建议您重新repo sync
我刚开始使用的是方法二但我又遇到了

Communication error with Jack server (52). Try 'jack-diagnose'

执行发现jack-diagnose没有可执行权限,添加之

chmod +x prebuilts/sdk/tools/jack-diagnose
./prebuilts/sdk/tools/jack-diagnose

然后继续make,继续Communication error,排查后发现一定要记得out/host/linux-x86/bin/jack-admin start-server
如果还不可以,那就先执行make clean,然后再执行一遍kill-serverstart-server,即

make clean
export JACK_SERVER_VM_ARGUMENTS="-Dfile.encoding=UTF-8 -XX:+TieredCompilation -Xmx4096m"
out/host/linux-x86/bin/jack-admin kill-server
out/host/linux-x86/bin/jack-admin start-server
make

emmm...95%,不不90%的问题,应该可能也许大概都可以解决了吧...接下来的情况可能要具体情况具体分析了

  1. file is empty
prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.15-4.8/x86_64-linux/bin/ld: error: out/host/linux-x86/obj32/EXECUTABLES/libaapt2_tests_intermediates/split/TableSplitter_test.o: file is empty

解决方法
ln -s /usr/bin/ld.gold prebuilts/gcc/linux-x86/host/x86_64-linux-glibc2.11-4.8/x86_64-linux/bin/ld

  1. emulator黑屏无响应
    如果是kerner内核问题:
    解决方法: 使用kernel-qemu-armv7内核
./out/host/linux-x86/bin/emulator -partition-size 1024 -kernel ./prebuilts/qemu-kernel/arm/kernel-qemu-armv7 

到此如果还没解决, 不妨尝试编译对应64位版本

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 205,132评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 87,802评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,566评论 0 338
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,858评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,867评论 5 368
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,695评论 1 282
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,064评论 3 399
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,705评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 42,915评论 1 300
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,677评论 2 323
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,796评论 1 333
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,432评论 4 322
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,041评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,992评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,223评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,185评论 2 352
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,535评论 2 343

推荐阅读更多精彩内容