2017-07-30 131 views
1

我試圖添加外部jar文件到我的android項目。這些外部罐子互相依賴,有些是依賴另一個,所以當有一個類位於另一個jar文件中的引用時,android studio會爲該類引發java.lang.NoClassDefFoundError。在android項目中添加外部依賴jar文件

什麼是在Android項目中使用這些罐子的正確解決方案?

compile files('libs/gt-shapefile-2.7.5.jar') 
compile files('libs/gt-metadata-2.7.5.jar') 
compile files('libs/gt-data-2.7.5.jar') 
compile files('libs/gt-main-2.7.5.jar') 
compile files('libs/gt-api-2.7.5.jar') 
compile files('libs/gt-referencing-2.7.5.jar') 
compile files('libs/vecmath-1.3.2.jar') 
compile files('libs/commons-pool-1.5.4.jar') 
compile files('libs/gt-opengis-2.7.5.jar') 
compile files('libs/jsr-275-1.0-beta-2.jar') 
compile files('libs/jts-1.11.jar') 
compile files('libs/jdom-1.0.jar') 
compile files('libs/jai_core-1.1.3.jar') 
compile files('libs/hsqldb-1.8.0.7.jar') 
compile files('libs/gt-epsg-hsql-2.7.5.jar') 

回答

1

你可以參考this答案以獲得正確的方式來添加jar庫。

  1. 首先打開你的文件夾結構從安卓到項目中。輸入 圖像描述enter image description here

  2. 現在搜索應用程序 - 生成文件夾內的libs文件夾。 enter image description here

  3. 將.jar文件粘貼到libs文件夾中後,右鍵點擊該文件的 ,最後點擊添加爲庫。這需要注意在build.gradle中添加編譯文件('libs/library_name.jar') [您的 不必在您的構建文件中手動輸入]。輸入的形象在這裏

    enter image description here

    說明現在就可以開始使用該庫在項目中。

+0

你可以參考這個答案,其中包括許多approuches。 https://stackoverflow.com/a/35369267/7592874 – Zacktamondo

+0

我做到了,沒有結果,並得到相同的錯誤 –

+0

@alirezarahmaty我認爲你應該確保這些庫也在其他庫內部實現。 – Zacktamondo

相關問題