我在将xstream库添加到基于Android gradle的应用程序时遇到了困难。从我在xstream文档中读到的内容来看,它应该可以开箱即用"开箱即用"。但是,当我添加依赖项时:
compile 'com.thoughtworks.xstream:xstream:1.4.8'
我在构建过程中遇到以下异常:
* What went wrong:
Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/xmlpull/v1/XmlPullParser.class
好的,也许我应该排除xmlpull?我尝试将此依赖项更改为:
compile ('com.thoughtworks.xstream:xstream:1.4.8') {
exclude group: 'xmlpull', module: 'xmlpull'
}
结果,过了一段时间后:
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.RuntimeException: Exception parsing classes
at com.android.dx.command.dexer.Main.processClass(Main.java:752)
// ...
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)
at com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)
// ...
1 error; aborting
我还使用gradle dependencies
检查了项目依赖项,但没有发现与xml相关的内容。
我的整个build.gradle
文件:
group 'myGroup'
version '1.0'
apply plugin: 'com.android.application'
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.5.0'
}
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
useLibrary 'org.apache.http.legacy'
defaultConfig {
applicationId "edu.foo.app"
minSdkVersion 19
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
//proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
}
repositories {
mavenCentral();
maven {
url 'https://repository-achartengine.forge.cloudbees.com/snapshot/'
}
}
dependencies {
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:design:23.1.1'
compile project(':Commons')
compile 'commons-io:commons-io:2.4'
compile 'commons-codec:commons-codec:1.10'
compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.4'
compile 'org.achartengine:achartengine:1.2.0'
compile 'com.google.code.gson:gson:2.4'
compile 'com.thoughtworks.xstream:xstream:1.4.8'
// compile ('com.thoughtworks.xstream:xstream:1.4.8') {
// exclude group: 'xmlpull', module: 'xmlpull'
// }
}
如何将xstream库包含到我的项目中?
答案 0 :(得分:9)
解决方案是将xstream降级到v1.4.7 并排除xmlpull。
compile ('com.thoughtworks.xstream:xstream:1.4.7') {
exclude group: 'xmlpull', module: 'xmlpull'
}
我不确切知道原因,但我猜它必须与java8相关。
答案 1 :(得分:0)
我得到了相同的错误。我做了什么,我只是从我的默认首选项中禁用“启用所有测试工件”。
和Open build variants选择单元测试..
希望上面的Ans可以帮助任何人。