windows平台下载android4.4源码
一.首先下载一个 msysgit,安装。
http://code.google.com/p/msysgit/downloads/list
二.
设置windows 的Path, 将msysgit的bin目录的绝对路径添加进去
三.
在D:\盘建一个目录 android
再在里面建一个目录 android4.4
cmd命令:
D:
mkdir android\android4.4
四.
下载android平台的所有分支信息
cmd命令:
git clone https://android.googlesource.com/platform/manifest.git D:\android
五.
选择系统版本分支
cmd 命令:
D:
cd android
cd manifest
git tag
这时候会列出很多版本, 通过下面的命令选择
git checkout android-4.4_r1
查看当前目录只剩下一个default.xml文件
ls
这个版本4.4的所有信息就在这个xml文件里面了
下面进行解析xml
六.
解析xml文件,并执行clone
通过c++实现
仔细查看xml文件,发现每一行其实就是一个clone信息
对于每一行执行get函数
例如get(line,"path");
string get(string line, string attribute) { string word; istringstream iss(line); while(iss>>word) { if(word[0]==attribute[0]){ size_t i=1; while((i<attribute.size())&&(i<line.size())){ if(attribute[i]!=word[i]) break; i++; } if(i==attribute.size()){ string res; int j=word.size()-1; while(j>-1){ if(word[j]=='\"'){ while(word[--j]!='\"'){ res = word[j]+res; } } --j; } return res; } } } return string(); }
七.
读取每一行,补充完整链接信息,进行clone
string get(string, string); int main() { //远程路径的前缀 string remoteRootPath = "https://android.googlesource.com/"; string localRootPath = "D:\\android\\android4.4\\"; string line; //xml 文件 ifstream xmlfile("D:\\android\\manifest\\default.xml"); string remotePath; string localPath; string path; string name; while(getline(xmlfile, line)) { path = get(line, "path"); name = get(line, "name"); for(size_t i=0; i< path.size(); ++i) if(path[i]=='/')path[i]='\\'; remotePath = remoteRootPath + name; localPath = localRootPath + path; string mkdir = "mkdir "+ localPath; string sys_call = "git clone " + remotePath + " " + localPath; if((path!="")&&(name!="")){ system(mkdir.c_str()); system(sys_call.c_str()); } } }
所需要的头文件
#include <iostream> #include <fstream> #include <sstream> #include <windows.h>
八.
正常启动clone的截图:
如果出现git 命令没找到:
1.可能msysgit没有安装
2.Path没有设置好
如果出现中途下载失败:
将失败时正在下载的那个目录删除,重新启动程序。(如果给程序加入日志信息,则不需要,但是这里没有实现)