打造自己的Android源码学习环境之四:下载Android源代码

打造自己的Android源码学习环境之四:下载Android源代码

下载android代码的全部指导来自:http://source.android.com/source/index.html
如果你访问不了这个网址,可以看看这个链接

注意,需要同时在主机系统(Host OS)和虚拟系统(Guest OS)中配置hosts。

0. 安装所需软件

0.1 安装JDK

参考: http://source.android.com/source/initializing.html

$ sudo apt-get update
$ sudo apt-get install openjdk-8-jdk

0.2 安装必要的软件包

参考: http://source.android.com/source/initializing.html

$ sudo apt-get install git-core gnupg flex bison gperf build-essential \
  zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 \
  lib32ncurses5-dev x11proto-core-dev libx11-dev lib32z-dev ccache \
  libgl1-mesa-dev libxml2-utils xsltproc unzip

0.3 安装Repo

参考: http://source.android.com/source/downloading.html

$ mkdir ~/bin
$ vim .bashrc

在.bashrc中添加PATH=~/bin:$PATH
然后使设置生效:

$ . ~/.bashrc

下载repo:

$ curl https://storage.googleapis.com/git-repo-downloads/repo > ~/bin/repo
$ chmod a+x ~/bin/repo

1. 下载Android源代码

1.1 创建目录,存放代码用

$ mkdir android
$ cd android/

1.2 配置git

$ git config --global user.name "galian"
$ git config --global user.email "xxx@yyy.com"
$ git config -l
user.name=galian
user.email=xxx@yyy.com

1.3 查询Branch

参考: http://source.android.com/source/build-numbers.html#source-code-tags-and-builds

这里写图片描述

准备下载android-7.1.1_r13分支对应的代码。

1.4 repo init

repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r13

一些log信息,如下:

$ repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r13
Get https://gerrit.googlesource.com/git-repo/clone.bundle
Get https://gerrit.googlesource.com/git-repo
Get https://android.googlesource.com/platform/manifest
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
curl: (22) The requested URL returned error: 404 Not Found
Server does not provide clone.bundle; ignoring.
remote: Counting objects: 410, done        
remote: Total 4566 (delta 1251), reused 4566 (delta 1251)        
接收对象中: 100% (4566/4566), 3.00 MiB | 2.60 MiB/s, 完成.
处理 delta 中: 100% (1251/1251), 完成.
来自 https://android.googlesource.com/platform/manifest
 * [新分支]          adt_23.0.3 -> origin/adt_23.0.3
 * [新分支]          afw-test-harness-1.5 -> origin/afw-test-harness-1.5
 * [新分支]          afw-test-harness-2.1 -> origin/afw-test-harness-2.1
 * [新分支]          afw-test-harness-marshmallow-dev -> origin/afw-test-harness-marshmallow-dev
 * [新分支]          afw-test-harness-nougat-dev -> origin/afw-test-harness-nougat-dev
 * [新分支]          android-1.6_r1 -> origin/android-1.6_r1
 * [新分支]          android-1.6_r1.1 -> origin/android-1.6_r1.1
 * [新分支]          android-1.6_r1.2 -> origin/android-1.6_r1.2

(省略)

 * [新分支]          android-7.0.0_r24 -> origin/android-7.0.0_r24
 * [新分支]          android-7.0.0_r27 -> origin/android-7.0.0_r27
 * [新分支]          android-7.0.0_r3 -> origin/android-7.0.0_r3
 * [新分支]          android-7.0.0_r4 -> origin/android-7.0.0_r4
 * [新分支]          android-7.0.0_r5 -> origin/android-7.0.0_r5
 * [新分支]          android-7.0.0_r6 -> origin/android-7.0.0_r6
 * [新分支]          android-7.0.0_r7 -> origin/android-7.0.0_r7
 * [新分支]          android-7.1.0_r1 -> origin/android-7.1.0_r1
 * [新分支]          android-7.1.0_r2 -> origin/android-7.1.0_r2
 * [新分支]          android-7.1.0_r3 -> origin/android-7.1.0_r3
 * [新分支]          android-7.1.0_r4 -> origin/android-7.1.0_r4
 * [新分支]          android-7.1.0_r5 -> origin/android-7.1.0_r5
 * [新分支]          android-7.1.0_r6 -> origin/android-7.1.0_r6
 * [新分支]          android-7.1.0_r7 -> origin/android-7.1.0_r7
 * [新分支]          android-7.1.1_r1 -> origin/android-7.1.1_r1
 * [新分支]          android-7.1.1_r10 -> origin/android-7.1.1_r10
 * [新分支]          android-7.1.1_r11 -> origin/android-7.1.1_r11
 * [新分支]          android-7.1.1_r12 -> origin/android-7.1.1_r12
 * [新分支]          android-7.1.1_r13 -> origin/android-7.1.1_r13

(省略)

Your identity is: galian <xxx@yyy.com>
If you want to change this, please re-run 'repo init' with --config-name

Testing colorized output (for 'repo diff', 'repo status'):
  black    red      green    yellow   blue     magenta   cyan     white 
  bold     dim      ul       reverse 
Enable color display in this user account (y/N)? Y

repo has been initialized in /home/galian/android

1.5 开始下载代码

$ repo sync

大概需要5~6个小时可以下载完成。

注意:为了确保全下载下来,再多执行一次repo sync

android 7.0.1r13的代码大概54GB,其中.repo目录34GB。除去.repo目录,代码大概20GB左右。

2. 可能出现的问题

2.1 Network is unreachable

$ repo init -u https://android.googlesource.com/platform/manifest -b android-7.1.1_r13
gpg: keyring `/home/galian/.repoconfig/gnupg/secring.gpg' created
gpg: keyring `/home/galian/.repoconfig/gnupg/pubring.gpg' created
gpg: /home/galian/.repoconfig/gnupg/trustdb.gpg: trustdb created
gpg: key 920F5C65: public key "Repo Maintainer <repo@android.kernel.org>" imported
gpg: key 692B382C: public key "Conley Owens <cco3@android.com>" imported
gpg: Total number processed: 2
gpg:               imported: 2  (RSA: 1)

fatal: Cannot get https://gerrit.googlesource.com/git-repo/clone.bundle
fatal: error [Errno 101] Network is unreachable

解决方法:
参考这个链接

$ sudo vim /etc/hosts

修改hosts文件后,执行

sudo apt-get install nscd
sudo /etc/init.d/nscd restart

2.2 unable to auto-detect email address

*** Please tell me who you are.

Run

  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'galian@galian-VirtualBox.(none)')

解决方法:

$ git config --global user.name "your_name"
$ git config --global user.email "xxx@yyy.com"

替换your_namexxx@yyy.com为你自己的信息。

3. 参考

(1) http://source.android.com/source/index.html
(2) http://source.android.com/source/initializing.html
(3) http://source.android.com/source/downloading.html
(4) http://source.android.com/source/build-numbers.html#source-code-tags-and-builds

———————– 分 割 线 ———————–
本系列文章如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值