在eclipse中關聯android原始碼方便開發

來源:互聯網
上載者:User


如何關聯原始碼:
把源碼解壓放在android.jar所在目錄的sources裡即可 比如我是基於android2.2開發,android.jar所在目錄為D:/Program Files/android-sdk-windows/platforms/android-8,在這個目錄下建立檔案夾sources,將源碼放入其中即可,開啟eclipse後,ADT會自動關聯到源碼

 

附:


擷取Android的Java原始碼並在Eclipse中關聯查看的最新方法

原始地址http://618119.com/archives/2011/01/01/201.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。
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.org 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的代碼:
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.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

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.