Can't add XStream file dependency to Android Studio project
Asked Answered
M

1

8

I have downloaded and added xstream-1.4.8.jar to my Android Studio project. When I build the project it works fine but when I try to run it I get the following error from the Gradle Build window:

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

I have looked at the related answers on here and none of the suggested solutions work for me.

Thanks in advance.

Mitziemitzl answered 9/3, 2015 at 15:41 Comment(0)
F
18

XStream 1.4.8 is compiled for Java 8 and the latest version Android supports is Java 7.

One solution is to use XStream 1.4.7, that works with Android, and another to download XStream 1.4.8 sources and compile them yourself. In that case you will have to remove LambdaMapper.java and possibly some other problematic classes.

Also you can have issues with different versions of xmlpull parser used. In that case you can exclude one from compiling.

compile('com.thoughtworks.xstream:xstream:1.4.7') {
    exclude group: 'xmlpull', module: 'xmlpull'
}
Falcone answered 10/3, 2015 at 18:39 Comment(5)
Hi, I worked that out shortly after posting the question. I am now using XStream 1.4.7. Thanks very much for your helpMitziemitzl
They now released 1.4.10-java7 It does not contain any stuff of Java 8.Biller
Android Plugin for Gradle 3.0.0 seems not to accept anymore the exclude command you posted. It works on 2.3.3 though. See #47335642Biller
@Biller Works fine for me. Maybe some other combination triggers the error. I could not build one project before I deleted .gradle folder from project (not XStream related error). Others didn't have such issues and all use XStream.Falcone
@DalijaPrasnikar You were right. I finally found the combination: #47335642Biller

© 2022 - 2024 — McMap. All rights reserved.