在Google搜索“AndroidEclipse 源代码”得到的结果并不合适,因为Google的EclipseAndroid开发插件已经更新到了ADT 8.0.1.相应的lib关联java源代码的方式也变了。
以下是获取Android的Java源代码并在Eclipse中关联的最新操作方法和步骤:
1.首先下载Android的SDK安装文件:http://dl.google.com/android/android-sdk_r08-windows.zip
然后解压到:E:\Java\android\android-sdk-windows,运行目录中的SDK Manager.exe,下载好Android不同版本的API包。

2.然后下载或在线安装Eclipse插件ADT,
安装包地址为:http://dl.google.com/android/ADT-8.0.1.zip
在线安装地址:https://dl-ssl.google.com/android/eclipse/
来源:ttp://developer.android.com/sdk/eclipse-adt.html

2.ADT插件安装好之后,下载我已经打包好的Android2.3(gingerbread)的java源代码压缩包:
下载地址:http://lizongbo.googlecode.com/files/android_gingerbread_javasrc.zip
来源:http://code.google.com/p/lizongbo/downloads/list
下载后复制到E:\Java\android\javasrc。

3.Android的Java源代码压缩包下载好之后,在Eclipse中设置好SDK配置:
操作步骤为:主菜单->Window–>Preferences–>选择Android,SDK Location设置为:E:\Java\android\android-sdk-windows,然后点右下角的Apply来生效。

4.开始进行关联Android的源代码,在Eclipse中新建一个Android工程,选中工程,主菜单 –>Project–>Properties–>选择Android,Project Build Target选中Android2.3。
然后再点左边的“JavaBuild Path”,切换到 Libraries 面板,展开 Android2.3 这个lib,点击android.jar的Source attachment,再点Edit.在对话框中点“External File”,选择E:/Java/android/javasrc/android_gingerbread_javasrc.zip,点OK进行确认。这样就把Android的java代码关联好了。

5.在同一个工程中,选中工程,主菜单–>Project–>Properties–>选择Android,Project Build Target分别选择Android1.5,Android1.6,Android2.01,Android2.1- update1,Android2.2,按上面第四步的操作重复设置关联。
以后在任何Android工程里按住Ctrl用鼠标点击Java类名都可以浏览到对应的java源代码。
Android各个版本对应的源代码为:
Android1.5对应android_cupcake_javasrc.zip
Android1.6对应android_donut_javasrc.zip
Android2.01和Android2.1-update1对应的是android_eclair_javasrc.zip
Android2.2对应android_froyo_javasrc.zip
Android2.3对应android_gingerbread_javasrc.zip

6.在Eclipse配置好源代码关联之后之后的信息会存储在:
E:\lizongbo\workspacenew\.metadata\.plugins\org.eclipse.core.resources\.root\.indexes\properties.index
E:\lizongbo\workspacenew\.metadata\.plugins\org.eclipse.jdt.core\variablesAndContainers.dat

同时记录Android的java源代码压缩包制作方法如下:
1.先在远程的UbuntuLinux服务器(是Linode VPS)上安装以下组件(JDK1.6已经安装好了):
sudo apt-get installgit-core gnupg flex bison gperf libsdl-dev libesd0-dev libwxgtk2.6-dev build-essential zip curl libncurses5-dev zlib1g-dev
信息来自Android官方:http://source.android.com/source/download.html
2.运行 sudo apt-get install lib32readline5-dev
3.安装Repo脚本:
我懒得配PATH了,于是直接安装到了/usr/local/bin。
root@lizongbo.com:~/bin# cd /usr/local/bin
root@lizongbo.com:/usr/local/bin# ls
geoip-lookup
root@lizongbo.com:/usr/local/bin# curlhttp://android.git.kernel.org/repo>/usr/local/bin/repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 17412 100 17412 0 0 27517 0 –:–:– –:–:– –:–:– 31148
root@lizongbo.com:/usr/local/bin# chmod a+x /usr/local/bin/repo
注意在下载该脚本的时候,可能会遇到服务器出错,下载的内容不对,运行命令的时候会提示错误“syntax error near unexpected token `newline’”。
root@lizongbo.com:/usr/local/bin# repo init -ugit://android.git.kernel.org/platform/manifest.git-b cupcake
/usr/local/bin/repo: line 1: syntax error near unexpected token `newline’
/usr/local/bin/repo: line 1: `<!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>’
root@lizongbo.com:/usr/local/bin# more repo
<!DOCTYPE HTML PUBLIC “-//IETF//DTD HTML 2.0//EN”>
<html><head>
<title>500 Internal Server Error</title>
</head><body>
<h1>Internal Server Error</h1>
<p>The server encountered an internal error or
misconfiguration and was unable to complete
your request.</p>
<p>Please contact the server administrator,
webmaster@kernel.organd inform them of the time the error occurred,
and anything you might have done that may have
caused the error.</p>
<p>More information about this error may be available
in the server error log.</p>
</body></html>
从内容看是服务器出错了,因此需要重新下载脚本.
4.建立mydroid目录,按代码分支下载对应版本的Android完整的源代码,比如下载Android2.3的代码:
root@lizongbo.com:~/mydroid# mkdir gingerbread
root@lizongbo.com:~/mydroid# cd gingerbread/
root@lizongbo.com:~/mydroid/gingerbread# repo init -ugit://android.git.kernel.org/platform/manifest.git-b gingerbread
root@lizongbo.com:~/mydroid/gingerbread# repo sync
Android1.5的代码分支:
root@lizongbo.com:~/mydroid/cupcake# repo init -ugit://android.git.kernel.org/platform/manifest.git-b cupcake
root@lizongbo.com:~/mydroid/cupcake# repo sync
Android1.6的代码分支:
root@lizongbo.com:~/mydroid/donut# repo init -ugit://android.git.kernel.org/platform/manifest.git-b donut
root@lizongbo.com:~/mydroid/donut# repo sync
Android2.0.1和2.1的代码分支:
root@lizongbo.com:~/mydroid/eclair# repo init -ugit://android.git.kernel.org/platform/manifest.git-b eclair
root@lizongbo.com:~/mydroid/eclair# repo sync
Android2.2的代码分支:
root@lizongbo.com:~/mydroid/froyo# repo init -ugit://android.git.kernel.org/platform/manifest.git-b froyo
root@lizongbo.com:~/mydroid/froyo# repo sync

如果遇到代码下载速度太慢,可以指定hosts,hosts配置不住为:
root@lizongbo.com:~/mydroid/gingerbread/.repo/projects# nslookup
>android.git.kernel.org
Server: 72.14.188.5
Address: 72.14.188.5#53
Non-authoritative answer:
android.git.kernel.org canonical name =android.git.geo.kernel.org.
android.git.geo.kernel.org canonical name =android.git.us.kernel.org.
Name:android.git.us.kernel.org
Address: 149.20.20.141
Name:android.git.us.kernel.org
Address: 204.152.191.45
> exit

root@lizongbo.com:/etc# vi hosts
204.152.191.45android.git.us.kernel.org
204.152.191.45android.git.kernel.org

网上有文章介绍使用提取java文件并打包的pytho脚本可以生成源代码包,参考:

http://android.opensourceror.org/2010/01/18/android-source/

http://blog.michael-forster.de/2008/12/view-android-source-code-in-eclipse.html
Python下载地址:http://www.python.org/ftp/python/2.6.6/python-2.6.6.msi
但是在Android2.2和Android2.3的代码里,Android写一了一些mock的类,比如android.webkit.WebView,使用python脚本打包的话,会把mock的源代码打进去,而不是真正的源代码,
因此我根据python脚本写了个java程序来提取java文件过滤冗余的java代码并打包。
生成的java源代码压缩:android_cupcake_javasrc.zip,android_donut_javasrc.zip,android_eclair_javasrc.zip,android_froyo_javasrc.zip,android_gingerbread_javasrc.zip
目前在code.google.com上传了android_gingerbread_javasrc.zip,欢迎下载。

以下是各版本的Androidjavasource 下载地址:

Android2.3:http://lizongbo.googlecode.com/files/android_gingerbread_javasrc.zip

Android1.5:http://lizongbo.googlecode.com/files/android_cupcake_javasrc.zip
Android1.6:http://lizongbo.googlecode.com/files/android_donut_javasrc.zip
Android2.1:http://lizongbo.googlecode.com/files/android_eclair_javasrc.zip
Android2.2:http://lizongbo.googlecode.com/files/android_froyo_javasrc.zip

更多相关文章

  1. Android开发实例源代码批量下载
  2. Android实现游戏摇杆的源代码
  3. Android Alarm驱动源代码分析(Alarm.c)
  4. Android脚本插件系列(一):安卓国际化多语自动合入脚本
  5. Android百度地图之位置定位和附近查找代码简单实现 (上)
  6. Android Studio中配置代码和资源的路径
  7. Android 代码设置EditText过滤汉字
  8. Android 新浪微博代码
  9. Android 长按显示上下文菜单代码

随机推荐

  1. Android(安卓)dependency has different
  2. Android获取3G或WiFi流量信息
  3. android查看so动态库的接口
  4. Android顶部菜单实现
  5. Android对话框之Context
  6. 修改Android(安卓)4.2 源码使支持softap
  7. 打开关闭android如何默认打开小区广播?
  8. “Unable to execute dex: Multiple dex
  9. Android下如何获取CPU序列号
  10. android美化短信聊天记录使得输入长短信