如何在android中使用java 8库? [英] How to use a java 8 library with android?
问题描述
我正在尝试使用在我的android项目中使用java 8的库。我无法找到一种方法来完成这项工作。我试过使用复古lambda但它没有帮助。我一直收到错误:com.android.dx.cf.iface.ParseException:bad class file magic(cafebabe)或version(0034.0000)
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)
我研究了这个并且了解它是因为包含的库中有java 8语法。我一直在使用java 8 sdk编译并使用android studio 08.2。救命!
图书馆是: https://github.com/robrua/Orianna
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
推荐答案
解决方案1
等待android支持Java8。
Solution 1
Wait for android to support Java8.
使用非Java8的早期版本库和/或要求库的开发人员提供一个/最后一个Java6(或Java7 for kitcat向上)库。
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.
这个是某种黑客,我还没有测试过甚至没用过它!
This is some kind of hack and I haven't tested or even used it!
使用 retrolambda 将Java8字节码反向移植到Java6。在retrolambda的主页上,您可以找到一些关于它的文档。
retrolambda的下载是这里。
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.
可能你必须将库jar解压缩到一个文件夹并运行如下命令:
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
也许您必须根据库的依赖关系扩展类路径。
然后你必须将生成的jar文件复制到android-project的lib文件夹中。
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.
也可以程序Java8 for android 。
如果retrolambda不起作用,也许你可以找到另一个工具来将Java8字节码反向移植到Java6字节码。
If retrolambda doesn't work maybe you can find another tool to backport Java8-bytecode to Java6-bytecode.
这篇关于如何在android中使用java 8库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!