天天看點

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

一、導入Android源碼

1.複制eclipse的classpath到Android源碼根目錄,路徑在\development\ide\eclipse下面

2.修改eclipse緩存設定

因為Android源碼體積比較大,加載需要更大的記憶體,把eclipse.ini檔案的3個值改為下面的值:

-Xms256m

-Xmx1024m

-XX:MaxPermSize=768m

3.導入eclipse代碼風格

把android-formatting.xml和android.importorder導入Eclipse

/development/ide/eclipse/android-formatting.xml

/development/ide/eclipse/android.importorder

4.導入Android源碼

建立Java Project(不是Android project):選擇從已存在的工程導入,定位到Android源碼的目錄進行導入即可。

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

最後效果圖如下:

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

5、移除不必要的代碼,很多時候,隻是需要學習源碼的某一部分,是以,沒有必要全部導入,可以選擇性的導入,這樣可以提升Eclipse的速度。編輯位于根目錄的.classpath檔案,移除不需要導入的選項。

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

這樣,就隻有部分導入了:

二、Debug Android源碼

1、先運作Genymotion 5.0的模拟器

2、選中項目,點選右鍵,選擇 Run->Debug Configurations... 選項。然後輕按兩下的 Remote Java Application就會彈出對話框:

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

把端口改為8700就好了。

3、打開DDMS,選擇要Debug的程序,點選綠色的甲蟲按鈕,比如調試ViewGroup的源碼,則選擇下面的程序:

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

然後再需要調試的地方打好斷點,就可以開始調試了:

Eclipse導入和調試 Android 5.0源碼一、導入Android源碼 二、Debug Android源碼

繼續閱讀