Android 無法查看外部依賴jar的源碼的問題

在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.

因此按照如下操作添加對應的源代碼:

選擇workspace 裏面的項目,點擊右鍵--->Build Path-->configure build path -->liberaries-->選擇一個jar包--->點擊左側的展開三角按鈕--->

展開後選擇Source attachment --->點擊右側的 Edit 按鈕--->彈出對話框,並選擇External File---->找到指定的源文件壓縮包。或者可使用外部源文件目錄。點擊OK。

進去以後發現還是不能查看,同樣的提示!

仔細讀英文的後半部分,在libs中直接引用的第三方jar包不讓其做任何修改。包括添加源文件參看。

因此在android工程下新建一個lib目錄,將jar包從libs轉移到lib中。然後重複以上過程。

結果就可以查看了!不過一運行你的程序,馬上報錯無法找到class的錯誤。 = =!  死衚衕了~

看來只能將第三方jar放到libs了。

有的牛人這樣解決了:

In order to link the sources and javadoc to a .jar library that is automatically linked by Eclipse you have to do the following.

  1. Place all three .jar files in the libs folder.
  2. Create .properties file in the libs folder with the name of the library .jar (see example).
  3. Specify the relative paths to the sources and javadoc .jar in the .properties file.
  4. Close and re-open the Eclipse project! Optionally refresh the project.
  5. Select an object of the linked library in the source code.
  6. Open the Javadoc view in Eclipse to check the documentation (see screenshot).
  7. Open the source code declaration (default shortcut: F3) of the selected object.

You can of course move the javadoc and sources .jar into other folders and specify relative paths. That's up to you.

enter image description here

但是遺憾的是,弄了半天都沒能解決。可能也跟我用的第三方的jar包不規範的原因,而且我沒有doc文件。


最終,我想到了一個解決辦法:

新建一個lib目錄

將需要的jar包全部拷貝到該目錄下

依次對每個jar包執行 上面綠色 部分操作

完成後右鍵lib目錄,點擊build path--> use as source folder

即可解決查看源碼的問題,也可使程序正常執行。


上面粗體字方法,親測可用。


3樓 youz1976 2014-11-27 23:55發表 [回覆] [引用] [舉報]
想看到百度地圖的源代碼,按這種方式試了還是不可以
2樓 l996243623 2014-05-08 00:27發表 [回覆]
在工程的libs目錄下新建一個.properties文件,命名爲android-support-v4.jar.properties 裏面寫上
src=D:\\Program Files\\adt-bundle-windowsx-86\\sdk\\extras\\android\\support\\v4\\src這是源碼的目錄(這是我的源碼路徑),windows系統要加雙反斜槓,Linux不用,就OK了。
Re: cyq1028 2014-07-25 14:42發表 [回覆]
回覆l996243623:太謝謝你的回覆了,原來我用的單斜槓,太坑了!
1樓 kinkabrain 2014-01-16 20:11發表 [回覆]
對於我來說,上面的方式都不行,最後是去修改工程目錄下的.classpath 文件,其中 <classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="gen"/> 這兩行的順序很重要!
然後在第二行添加jar包對應的源工程:
<classpathentry kind="lib" path="libs/mysdk.jar" sourcepath="/mysdk"/>





發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章