轉:
http://618119.com/archives/2010/12/29/198.html
在google搜尋“android eclipse 源代碼”得到的結果并不合适,因為google的eclipse android開發插件已經更新到了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插件安裝好之後,下載下傳我已經打包好的android 2.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選中android 2.3。
然後再點左邊的“java build 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.先在遠端的ubuntu linux伺服器(是linode vps)上安裝以下元件(jdk1.6已經安裝好了):
sudo apt-get install git-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。
[email protected]:~/bin# cd /usr/local/bin
[email protected]:/usr/local/bin# ls
geoip-lookup
[email protected]:/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
[email protected]:/usr/local/bin# chmod a+x /usr/local/bin/repo
注意在下載下傳該腳本的時候,可能會遇到伺服器出錯,下載下傳的内容不對,運作指令的時候會提示錯誤“syntax error near unexpected token `newline’”。
[email protected]:/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”>’
[email protected]:/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,
[email protected] and 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的代碼:
[email protected]:~/mydroid# mkdir gingerbread
[email protected]:~/mydroid# cd gingerbread/
[email protected]:~/mydroid/gingerbread# repo init -ugit://android.git.kernel.org/platform/manifest.git -b gingerbread
[email protected]:~/mydroid/gingerbread# repo sync
android1.5的代碼分支:
[email protected]:~/mydroid/cupcake# repo init -ugit://android.git.kernel.org/platform/manifest.git -b cupcake
[email protected]:~/mydroid/cupcake# repo sync
android1.6的代碼分支:
[email protected]:~/mydroid/donut# repo init -ugit://android.git.kernel.org/platform/manifest.git -b donut
[email protected]:~/mydroid/donut# repo sync
android2.0.1和2.1的代碼分支:
[email protected]:~/mydroid/eclair# repo init -ugit://android.git.kernel.org/platform/manifest.git -b eclair
[email protected]:~/mydroid/eclair# repo sync
android2.2的代碼分支:
[email protected]:~/mydroid/froyo# repo init -ugit://android.git.kernel.org/platform/manifest.git -b froyo
[email protected]:~/mydroid/froyo# repo sync
如果遇到代碼下載下傳速度太慢,可以指定hosts,hosts配置不住為:
[email protected]:~/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
address: 204.152.191.45
> exit
[email protected]:/etc# vi hosts
204.152.191.45 android.git.us.kernel.org
204.152.191.45 android.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,歡迎下載下傳。
以下是各版本的android java source 下載下傳位址:
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