Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use a java 8 library with android?

Tags:

java

android

I'm trying to use a library that uses java 8 in my android project. I cannot find a way to make this work. I've tried to use retro lambda but it has not helped. I keep getting the error: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version(0034.0000)

I've researched this and learned it's because there is java 8 syntax in the included library. I've been compiling with java 8 sdk and am using android studio 08.2. Help! The library is:https://github.com/robrua/Orianna

like image 486
user3847576 Avatar asked Jul 17 '14 04:07

user3847576


1 Answers

Solution 1

Wait for android to support Java8.

Solution 2

Use an earlier version of the library that isn't Java8 and/or ask the developer of the library to provide one/ the last Java6 (or Java7 for kitcat upwards) library.

Solution 3

This is some kind of hack and I haven't tested or even used it!

Use retrolambda to backport the Java8-bytecode to Java6. On the homepage of retrolambda you find some documentation about it. Downloads of retrolambda are here.

Probably you will have to unzip the library jar to a folder and the run a command like the following:

java -Dretrolambda.inputDir=<extracted_classfiles>
     -Dretrolambda.classpath=<extracted_classfiles>
     -Dretrolambda.bytecodeVersion=50
     -javaagent:retrolambda.jar
     -jar retrolambda.jar

Maybe you have to extend the classpath depending on the dependencies of the library. Then you have to copy the resulting jar-file into your android-project's lib folder.

It is also possible to program Java8 for android.

If retrolambda doesn't work maybe you can find another tool to backport Java8-bytecode to Java6-bytecode.

like image 63
AlexS Avatar answered Oct 22 '22 07:10

AlexS