对于Android开发的学习者来说,当学习和开发实践进行到了一定的阶段,就应该深入到Android系统的源代码中去了。 通过对源代码的研究、学习,可以熟悉Android发布的基本应用模块如Launcher、Contact、Email等的实现原理和开发方式,还可以深入到framework框架层、核心库层、Linux Kernel层等底层模块。 那么,怎么才能获取到Android的源代码呢? Android官方网站http://source./source/downloading.html对源代码的下载有详细的介绍,大家可以按照网站上介绍的方法一步步操作就可以了。 本文向大家介绍的是如何只对个别目录进行下载的方法,因为一方面由于网速的原因,很多时候完整下载所有的代码是办不到的,另一方面,我们可能只关心个别目录的源代码而已。 需要指出的是,Andrid的的源代码需要在Linux环境下下载的,在Windows环境下下载源代码的话大家可以安装Cygwin工具(PS:用Cygwin还可以在Windows下开发Android NDK 应用),配置好后下载方法是一样的。 好了,单个目录源码下载的具体步骤是: 第一步,按照官方网站的方法配置好git 和repo及相关的环境变量。 第二步,用 git clone方法对感兴趣的目录分别下载。 对于第二步,我们可以参考下面的例子。 源代码所在的地址是:http://android.git./ 如果我们要对所有的Android源代码进行下载,下载命令是: repo init -u git://android.git./platform/manifest.git repo sync 当然,如果我们只想下载Android 2.3 gingerbread版的完整源代码,加上分支选项: repo init -u git://android.git./platform/manifest.git –b gingerbread repo sync 好了,如果只想下载单个目录的代码,参见下面的例子: 仅下载Launcher: git clone git://android.git./platform/packages/apps/Launcher2.git 仅下载 Android 2.2 froyo版的Launcher: git clone git://android.git./platform/packages/apps/Launcher2.git –b froyo 分别下载Android 2.2 froyo版的framework的各个目录: git clone git://android.git./platform/frameworks/base.git -b froyo git clone http://android.git./platform/frameworks/base.git -b froyo git clone http://android.git./platform/frameworks/policies/base.git -b froyo git clone http://android.git./platform/frameworks/ex.git -b froyo git clone http://android.git./platform/frameworks/opt/com.google.android.git -b froyo git clone http://android.git./platform/frameworks/opt/com.google.android.googlelogin.git -b froyo git clone http://android.git./platform/frameworks/opt/emoji.git -b froyo 对于如何完整下载Android源代码的更多细节,大家也可以参考下下面链接里的介绍: http://www.cnblogs.com/chunhui588/archive/2010/07/04/using-git-repo-to-get-android-sourcecode.html 下面是其转帖: 使用Git和Repo获取Android源码 |
|