Android開發技巧之查看外部依賴jar的源碼_android private libralies does not allow modifications to source

來源:互聯網
上載者:User

標籤:android   jar   eclipse   

在Eclipse中開發android的應用程式時,有時想查看函數的內部實現,但是當在函數上點擊ctrl和滑鼠左鍵的時候,

往往出現如下提示: 

Class File Editor

Source not found

The JAR of this class file belongs to container ‘Android‘  which does not allow modifications to source attachments on its entries.

最普遍常見的是android-support-v4沒法看到其中的注釋和原始碼,滑鼠放到類上提示:

Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found.

 

一般來說如果環境配置好了,Android的所有類和所有方法都能看到其代碼和注釋,以下分兩步,將注釋和代碼全部配置正確。

1.Android本身jar包的原始碼

這裡假設已經把需要下載的都下載下來了,右鍵項目====》build path====》configure build path

在libraries裡選擇Android x.x.x裡面有Android.jar,這就是開發時所依賴的Android本身的sdk的jar包,點開,裡面有兩個需要配置,

source attachment和javadoc location,前者是原始碼,配置好後可實現ctrl+滑鼠左鍵直接點開想看的Android的類,

後者是原始碼的注釋檔案,配置好後可實現滑鼠放在想看到類上,會顯示出來這個類或者方法的介紹

選擇source attachment配置項,點擊右邊edit,選擇external location===》external folder,然後找到正確的路徑,我的是在E:/eclipse/sdk/sources/android-19

選擇javadoc location配置項,edit,選擇javadoc url===》browse,然後找到正確路徑,我的是在file:/E:/eclipse/sdk/docs/reference

完成上面這些就可以正常查看Android內部常用的類注釋和原始碼了

 

2.查看外部依賴jar包的原始碼

這裡假設你已經把外部依賴的jar包正確匯入並且編譯通過了,但是ctrl+滑鼠左鍵想看代碼或者想看其注釋卻不可行的情況,

首先在libs下面找到引入的包,這裡以android-support-v4.jar為例,

在libs下建立android-support-v4.jar.properties檔案,即與引用的jar包同名最後加上.properties的檔案

其內容如下:

src = E:\\eclipse\\sdk\\extras\\android\\support\\v4\\src

這裡路徑要根據你自己的路徑進行調整,配置之後退出eclipse,在進入,就可以正常查看了。

 

jason0539

微博:http://weibo.com/2553717707

部落格:http://blog.csdn.net/jason0539(轉載請說明出處)

 

Android開發技巧之查看外部依賴jar的源碼_android private libralies does not allow modifications to source

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.