Error while build with using newest Android Studio 2.1 and java 8

3,996 views
Skip to first unread message

vklein

unread,
Apr 28, 2016, 2:58:54 PM4/28/16
to mapsforge-dev
I set up a developement environment on a brandnew Windows 10 machine with Android Studio 2.1 and java SDK  1.8.0_92.
Java 8 is recommended on the android page.
Then I imported a well running testproject ( based on samples.mapsforge-master0.6) from a older Win7 machine with Java 1.7.0_71 and Studio 1.3.2
After solving some problems with the plugin and build tools, the build was succesfull.

But if I use the run button to build and install on a device I get a lot of errors.

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

Any suggestions?

There is  something like that in  build.gradle in the project

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

I did not change any of the gradle files from samples

This is what I got:
------------------------------------------------------------------------------
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.

from Gradle console

To run dex in process, the Gradle daemon needs a larger heap.
It currently has approximately 910 MB.
For faster builds, increase the maximum heap size for the Gradle daemon to more than 2048 MB.
To do this set org.gradle.jvmargs=-Xmx2048M in the project gradle.properties.
For more information see https://docs.gradle.org/current/userguide/build_environment.html

AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)\n\tat com.android.dx.command.dexer.Main.run(Main.java:275)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 21 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)\n\tat com.android.dx.command.dexer.Main.run(Main.java:275)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 21 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)\n\tat com.android.dx.command.dexer.Main.run(Main.java:275)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 21 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)\n\tat com.android.dx.command.dexer.Main.run(Main.java:275)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 21 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"Error converting bytecode to dex:\nCause: Dex cannot parse version 52 byte code.\nThis is caused by library dependencies that have been compiled using Java 8 or above.\nIf you are using the \u0027java\u0027 gradle plugin in a library submodule add \ntargetCompatibility \u003d \u00271.7\u0027\nsourceCompatibility \u003d \u00271.7\u0027\nto that submodule\u0027s build.gradle file.","sources":[{}],"original":"UNEXPECTED TOP-LEVEL EXCEPTION:\njava.lang.RuntimeException: Exception parsing classes\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:752)\n\tat com.android.dx.command.dexer.Main.processFileBytes(Main.java:718)\n\tat com.android.dx.command.dexer.Main.access$1200(Main.java:85)\n\tat com.android.dx.command.dexer.Main$FileBytesConsumer.processFileBytes(Main.java:1645)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:170)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)\n\tat com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)\n\tat com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)\n\tat com.android.dx.command.dexer.Main.processOne(Main.java:672)\n\tat com.android.dx.command.dexer.Main.processAllFiles(Main.java:574)\n\tat com.android.dx.command.dexer.Main.runMultiDex(Main.java:366)\n\tat com.android.dx.command.dexer.Main.run(Main.java:275)\n\tat com.android.dx.command.dexer.Main.main(Main.java:245)\n\tat com.android.dx.command.Main.main(Main.java:106)\nCaused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000)\n\tat com.android.dx.cf.direct.DirectClassFile.parse0(DirectClassFile.java:472)\n\tat com.android.dx.cf.direct.DirectClassFile.parse(DirectClassFile.java:406)\n\tat com.android.dx.cf.direct.DirectClassFile.parseToInterfacesIfNecessary(DirectClassFile.java:388)\n\tat com.android.dx.cf.direct.DirectClassFile.getMagic(DirectClassFile.java:251)\n\tat com.android.dx.command.dexer.Main.parseClass(Main.java:764)\n\tat com.android.dx.command.dexer.Main.access$1500(Main.java:85)\n\tat com.android.dx.command.dexer.Main$ClassParserTask.call(Main.java:1684)\n\tat com.android.dx.command.dexer.Main.processClass(Main.java:749)\n\t... 21 more\n","tool":"Dex"}
AGPBI: {"kind":"error","text":"5 errors; aborting","sources":[{}]}

:Applications:Android:Samples:transformClassesWithDexForOldpermissionsDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':Applications:Android:Samples:transformClassesWithDexForOldpermissionsDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_92\bin\java.exe'' finished with non-zero exit value 1

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Emux

unread,
Apr 28, 2016, 3:15:59 PM4/28/16
to mapsfo...@googlegroups.com
Android development still needs JDK 7 to be on the safe side.
(with Android N will see JDK 8).

Java 8 is the required version of Java that the latest IDE itself runs with.

The report mentions that if using the 'java' gradle plugin there is need to declare the two compatibilities.

--
Emux

vklein

unread,
May 1, 2016, 11:51:29 AM5/1/16
to mapsforge-dev
Does this mean that I have to install Java 7 too and let the sdk point to Java7?

Emux

unread,
May 1, 2016, 11:54:50 AM5/1/16
to mapsfo...@googlegroups.com
Yes you can try that.

--
Emux

Alex D.

unread,
Jun 14, 2016, 12:40:36 PM6/14/16
to mapsforge-dev
I  don't have the impression that anyone knows how to deal with this.

see also https://groups.google.com/d/topic/mapsforge-dev/_IsCJXXnTBg/discussion ?

so it is mapsforge that requires Java 7, and can't handle Java 8?

I'm using AS 2.1.2 JRE 1.8

I can't get this to work, I keep getting loads of

"Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file."

I've set "1.7" everywhere possible via the project structure dialog, run Clean, Rebuild , to no avail.

 (also:
Error:Execution failed for task ':mapsforge-samples-android:transformClassesWithDexForOldpermissionsDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_77\bin\java.exe'' finished with non-zero exit value 1
)

did someone solve this issue?

-alex-

Alex D.

unread,
Jun 14, 2016, 12:55:22 PM6/14/16
to mapsforge-dev
OK, so the solution is to install JDK 7...

But why do I have to go through this process to only then discover that I need a file called germany.map? why isn't this explained in the Android sample page?

issue created: https://github.com/mapsforge/mapsforge/issues/840

-alex-.

Emux

unread,
Jun 14, 2016, 1:03:18 PM6/14/16
to mapsfo...@googlegroups.com
I tested Mapsforge Maven artifacts and GettingStarted example with Java 7 and 8 on latest AS in a clean project and work with both JDK.

About needed map file see answer in related issue.

--
Emux
Reply all
Reply to author
Forward
0 new messages