This is caused by library dependencies that have been compiled using Java 8 or above.

来源:互联网 发布:python 打开html文件 编辑:程序博客网 时间:2024/05/20 22:28

1.错误现象

        在用android studio编译项目的时候提示错误:

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....while parsing android/support/led/app/LedHalService.class
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> 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: Error while executing java process with main class com.android.dx.command.Main with arguments {--dex --num-threads=4 --output /opt/FriendlyARM/LED_Drivers0420/Topic10/LedHAL/app/build/intermediates/pre-dexed/debug/LedHalService_c20efee379c8b345d133fb96ed6915725bb338c1.jar /opt/FriendlyARM/LED_Drivers0420/Topic10/LedHAL/app/libs/LedHalService.jar}

2.问题分析和解决

    出现这个问题是因为库的编译器版本和当前项目编译器版本不对应,导致编译出来的目标文件不能链接在一起。解决方法就是让android studio适配这个版本的编译器,按照错误的提示在gradle build添加:

targetCompatibility = '1.7'sourceCompatibility = '1.7'
然而再次编译的时候依然提示错误。

       看来android studio不能自动适配这个java编译器版本不对的问题,那就必须更改linux默认的JAVA编译器版本,输入两个命令即可更改:

root@g450:/opt/android-studio/jre/bin# update-alternatives --config java有 2 个候选项可用于替换 java (提供 /usr/bin/java)。  选择       路径                             优先级  状态------------------------------------------------------------  0            /usr/lib/jvm/jdk1.8.0_74/bin/java   300       自动模式* 1            /usr/lib/jvm/jdk1.6.0_43/bin/java   1         手动模式  2            /usr/lib/jvm/jdk1.8.0_74/bin/java   300       手动模式要维持当前值[*]请按回车键,或者键入选择的编号:1root@g450:/opt/android-studio/jre/bin# update-alternatives --config javac有 2 个候选项可用于替换 javac (提供 /usr/bin/javac)。  选择       路径                              优先级  状态------------------------------------------------------------  0            /usr/lib/jvm/jdk1.8.0_74/bin/javac   300       自动模式* 1            /usr/lib/jvm/jdk1.6.0_43/bin/javac   1         手动模式  2            /usr/lib/jvm/jdk1.8.0_74/bin/javac   300       手动模式要维持当前值[*]请按回车键,或者键入选择的编号:1

注意:只更改java的版本还是解决不了问题,必须同时更改javac的版本才可以。



    

阅读全文
0 0