0

All of the sudden my app stopped building in Android Studio. The message:

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 pl/qus/xenoamp/helper/XenoScala$.class 1 error; aborting

I didn't change JDK version or AS version...

But then I've checked default Java environment and it was set to 1.8. Changing it to 1.7 gave different error:

Error:Cause: scala/util/Properties$ : Unsupported major.minor version 52.0

More info: although my Scala library is compiled for 60.0 (Java 6), during build gradle caches a version that is built indeed for 52.0 in:

~.gradle\caches\modules-2\files-2.1\org.scala-lang\scala-library\2.12.0-M2\8453b80505a57d429f321b94e1fb4ca09b037fc0

What's wrong? What can I do?!

ssuukk
  • 8,200
  • 7
  • 35
  • 47

3 Answers3

0

According to this answer, it appears that the cause of the ParseException is the use of Java 1.8.

It appears that the "Unsupported major.minor version 52.0" error is due to the runtime being incompatible with the compile time code. I believe that major.minor 52.0 corresponds with Java 1.8, whereas 51.0 with Java 1.7. Likely by completely rebuilding your project with Java 1.7 will make the problem go away.

Community
  • 1
  • 1
Paul Lammertsma
  • 37,593
  • 16
  • 136
  • 187
0

Switch to 1.7 and make sure any libraries you depend on (in particular, the scala standard library) are built for 1.7 - from that error it seems the scala.util.Properties on your classpath (i.e. the scala standard library) was built for 1.8.

lmm
  • 17,386
  • 3
  • 26
  • 37
  • If you could only help me with scala standard library location on Windows... Is it just in Scala installation directory? I was pretty sure I've seen info that Scala was using 6 bytecode on Scala home page, do you think the newest package is compiled to 8? Oh, see: The Scala 2.11.x series targets Java 6, with (evolving) experimental support for Java 8. In 2.11.1, Java 8 support is mostly limited to reading Java 8 bytecode and parsing Java 8 source. Stay tuned for more complete (experimental) Java 8 support. The next major release, 2.12, will most likely target Java 8 by default. – ssuukk Jul 20 '15 at 09:43
  • I've found the lib and verified that this concrete class was compiled for 50.0 (which is Java 6), so something else must be wrong! – ssuukk Jul 20 '15 at 10:12
  • hmmm... but my Android studio somehow recompiles it as 52.0 in ~\.gradle\caches\modules-2\files-2.1\org.scala-lang\scala-library\2.12.0-M2\8453b80505a57d429f321b94e1fb4ca09b037fc0 – ssuukk Jul 20 '15 at 10:42
0

OK, again for future reference. This was caused by a small change in build.gradle. From

compile 'org.scala-lang:scala-library:2.11.+'

to

compile 'org.scala-lang:scala-library:2.+'

Scala 2.11 is compiled to Java 6, Scala 2.12 - to Java 8

ssuukk
  • 8,200
  • 7
  • 35
  • 47