发布时间:2025-12-09 13:57:49 浏览次数:4
打造自己的Android源码学习环境之四:下载Android源代码
下载android代码的全部指导来自:http://source.android.com/source/index.html。
如果你访问不了这个网址,可以看看这个链接。
注意,需要同时在主机系统(Host OS)和虚拟系统(Guest OS)中配置hosts。
参考: http://source.android.com/source/initializing.html
$ sudo apt-get update$ sudo apt-get install openjdk-8-jdk参考: 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参考: http://source.android.com/source/downloading.html
$ mkdir ~/bin$ vim .bashrc在.bashrc中添加PATH=~/bin:$PATH。
然后使设置生效:
$ . ~/.bashrc下载repo:
$ curl https://storage.proxy.ustclug.org/git-repo-downloads/repo > ~/bin/repo$ chmod a+x ~/bin/repo$ mkdir android$ cd android/$ git config --global user.name "galian"$ git config --global user.email "xxx@yyy.com"$ git config -luser.name=galianuser.email=xxx@yyy.com参考: http://source.android.com/source/build-numbers.html#source-code-tags-and-builds
准备下载android-7.1.1_r13分支对应的代码。
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_r13Get https://gerrit.googlesource.com/git-repo/clone.bundleGet https://gerrit.googlesource.com/git-repoGet https://android.googlesource.com/platform/manifest% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0curl: (22) The requested URL returned error: 404 Not FoundServer 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-nameTesting 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)? Yrepo has been initialized in /home/galian/android$ repo sync大概需要5~6个小时可以下载完成。
注意:为了确保全下载下来,再多执行一次repo sync
android 7.0.1r13的代码大概54GB,其中.repo目录34GB。除去.repo目录,代码大概20GB左右。
$ 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 createdgpg: key 920F5C65: public key "Repo Maintainer <repo@android.kernel.org>" importedgpg: key 692B382C: public key "Conley Owens <cco3@android.com>" importedgpg: Total number processed: 2gpg: 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 nscdsudo /etc/init.d/nscd restart*** Please tell me who you are.Rungit 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_name和xxx@yyy.com为你自己的信息。
(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
———————– 分 割 线 ———————–
本系列文章如下: