2013-07-10 48 views
2

要解決以下錯誤meassage無法執行DEX:多DEX文件定義Lorg/springframework的/ HTTP/HttpEntity

java.lang.NoClassDefFoundError:org.springframework.http.converter.xml.Jaxb2RootElementHttpMessageConverter

我添加了「spring-web-3.0.2.jar」來構建android應用程序的路徑,並在JavaBuildpath中的「順序和導出」中選擇該jar(properties-> buildpath-> order和Export)。

在添加這個perticular(spring-web-3.0.2.jar)後,它修復了「java.lang.NoClassDefFoundError」但它在嘗試運行我的應用程序時拋出了錯誤的錯誤。

Dex Loader]無法執行dex:多個dex文件定義了Lorg/springframework/http/HttpEntity; 轉換爲Dalvik格式失敗:無法執行dex:多個dex文件定義了Lorg/springframework/http/HttpEntity;

我在做什麼Worng?是因爲包含Lorg/springframework/http/HttpEntity的多個jar。

Follwing是我在我的項目中添加的jar。

  1. 簡單的XML-2.7
  2. 彈簧的Android認證 - 1.0.1.RELEASE
  3. 彈簧Android的核心1.0.1.RELEASE
  4. 彈簧Android的休息,模板 - 1.0.1.RELEASE
  5. 彈簧網絡3.0.2.RELEASE

我怎樣才能解決這個問題?任何幫助非常appricated。

回答

2

我認爲不需要spring-web-3.0.2.RELEASE,嘗試刪除它並再次檢查。那個錯誤是因爲Dalvik虛擬機找到了兩個具有相同名稱和包的類。

org.springframework.http.HttpEntity存在於Spring Android和Spring-web中。

+0

感謝您的建議,這是我以前也試過,它給我的類不錯誤,我在問題中提到。如果我添加它給我以下錯誤。 「Dex Loader」無法執行dex:多個dex文件定義Lorg/springframework/http/HttpEntity;轉換爲Dalvik格式失敗:無法執行dex:多個dex文件定義Lorg/springframework/http/HttpEntity;「 – user2559548

2

看看這篇文章,它似乎是相關的,尤其是羅伊的回答

http://forum.spring.io/forum/spring-projects/android/743289-importing-android-spring-with-gradle-cause-error-mutiple-dex-files

The Spring for Android rest-template and core artifacts do not have a dependency on spring core or any Spring Framework library. However, the auth dependency does, along with Spring Social. You can exclude globally like the following, then you don't have to repeat the exclusion for each dependency. I also agree about the frustration with the packagingOptions in the newer Android Gradle plugin versions. It really should support a wildcard so you don't have to declare all those individually. Hopefully, Google will add that in the future. Code:

configurations.compile { 
     exclude module: 'spring-core' 
     exclude module: 'spring-web' 
     exclude module: 'commons-logging' 
    } 
相關問題