2013-07-10 50 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' 
    } 
相关问题