无法将XStream文件依赖项添加到Android Studio项目中

我已下载并将xstream-1.4.8.jar添加到我的 Android Studio项目中.当我构建项目时它工作正常,但是当我尝试运行它时,我从Gradle Build窗口中收到以下错误
information:Gradle tasks [:app:assembleDebug]
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72103Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42103Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
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)
    at com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)
    at com.android.dx.cf.direct.DirectClassFile.parsetoInterfacesIfNecessary(DirectClassFile.java:388)
    at com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)
    at com.android.dx.command.dexer.Main.processClass(Main.java:704)
    at com.android.dx.command.dexer.Main.processFileBytes(Main.java:673)
    at com.android.dx.command.dexer.Main.access$300(Main.java:83)
    at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:602)
    at com.android.dx.cf.direct.ClasspathOpener.processArchive(ClasspathOpener.java:284)
    at com.android.dx.cf.direct.ClasspathOpener.processOne(ClasspathOpener.java:166)
    at com.android.dx.cf.direct.ClasspathOpener.process(ClasspathOpener.java:144)
    at com.android.dx.command.dexer.Main.processOne(Main.java:632)
    at com.android.dx.command.dexer.Main.processAllFiles(Main.java:510)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:280)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
...while parsing com/thoughtworks/xstream/mapper/Lambdamapper.class
1 error; aborting
Error:Execution Failed for task ':app:preDexDebug'.

com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:\Program Files\Java\jdk1.8.0_25\bin\java.exe” finished with non-zero exit value 1
information:BUILD Failed
information:Total time: 14.974 secs
information:1 error
information:0 warnings
information:See complete output in console

在这里看了相关的答案,并没有一个建议的解决方案适合我.

提前致谢.

XStream 1.4.8是针对Java 8编译的,Android支持的最新版本是Java 7.

一种解决方案是使用适用于Android的XStream 1.4.7,另一种解决方案是下载XStream 1.4.8源代码并自行编译.在这种情况下,您将不得不删除Lambdamapper.java以及可能的其他一些有问题的类.

此外,您可能会遇到使用不同版本的xmlpull解析器的问题.在这种情况下,您可以从编译中排除一个.

compile('com.thoughtworks.xstream:xstream:1.4.7') {
    exclude group: 'xmlpull',module: 'xmlpull'
}

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...