Google官方下载源码使用的系统Ubuntu系统,不过现在我们需要在Windows系统中下载Android源码文件。
网站的地址是:https://android.googlesource.com/
里面包括Android系统各个部分的源码,我们只需要下载platform就行
点击进入即可看到下载地址
地址是:https://android.googlesource.com/platform/manifest
1.准备工作
Android的源代码管理使用的是Git,所以安装Git必不可少,Windows系统中使用的是mysysgit目前的版本是Git-1.9.5-preview20150319.exe,自行搜索下载。源代码下载是使用Python脚本来完成的,所以还需要安装一个python环境。
2.下载XML描述文件
进入一个文件夹,用来存储XML描述文件,打开Git Bash执行如下命令
1
|
git clone https:
//android
.googlesource.com
/platform/manifest
|
不出意外的话很快就会下载完成,如果出现中断,请使用科学上网的方法重新下载,这里推荐一个乱炖hosts:http://levi.yii.so/archives/3553
下载完成后,执行如下命令:
1
|
git tag
|
选择相需要下载的版本,然后执行如下命令,检出相应的版本信息,这里已android-5.1.1_r8为例:
1
|
git checkout android-5.1.1_r8
|
在default.xml文件中就定义了android源码的路径。
3.编写python脚本下载源码
文件内容如下,然后再进行具体解释:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
import
xml.dom.minidom
import
os
from
subprocess
import
call
#downloaded source path
rootdir
=
"D:/Android/source/android-5.1.1_r8"
#git program path
git
=
"C:/Program Files (x86)/Git/bin/git.exe"
dom
=
xml.dom.minidom.parse(
"D:/Android/source/manifest/default.xml"
)
root
=
dom.documentElement
prefix
=
git
+
" clone https://android.googlesource.com/"
suffix
=
".git"
if
not
os.path.exists(rootdir):
os.mkdir(rootdir)
for
node
in
root.getElementsByTagName(
"project"
):
os.chdir(rootdir)
d
=
node.getAttribute(
"path"
)
last
=
d.rfind(
"/"
)
if
last !
=
-
1
:
d
=
rootdir
+
"/"
+
d[:last]
if
not
os.path.exists(d):
os.makedirs(d)
os.chdir(d)
cmd
=
prefix
+
node.getAttribute(
"name"
)
+
suffix
call(cmd)
|
第6行:rootdir 表示源码的存储路径
第9行:git 表示git的安装路径
第11行:刚刚下载检出的default.xml文件路径
如果路径有不同的地方,根据自己的境况修改
最后一步就是执行这个python脚本进行下载,,,等着吧。。。
1
|
python download
-
src.py
|