【问题标题】:I replace java 8 with java 7 android studio error?我用 java 7 android studio 错误替换 java 8?
【发布时间】:2016-07-11 14:05:33
【问题描述】:

为什么我用 JAVA 7 替换 JAVA 8,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.
Error:...while parsing android/support/v7/recyclerview/R$attr.class
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:...while parsing android/support/v7/recyclerview/R$dimen.class
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:...while parsing android/support/v7/recyclerview/R$id.class
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:...while parsing android/support/v7/recyclerview/R$styleable.class 
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:...while parsing android/support/v7/recyclerview/R.class
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:...while parsing com/example/administrator/comjarlib/R$anim.class
Error:Error converting bytecode to dex:
............

我想在 Android Studio 中使用 retroLambda。

遇到类似问题/已解决的任何人都可以提供一些解决方法。

我正在使用 2.10 级的 Android Studio 2.1 Preview 3

【问题讨论】:

  • 您是否尝试将这两行添加到您的 build.gradle 文件中?
  • 您阅读了错误日志吗? 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.

标签: android android-studio


【解决方案1】:

这个帮助了我。在您项目的主 build.gradle 文件中,将这些代码行添加到 allprojects 部分(如果不存在则添加此部分)。

allprojects {

    tasks.withType(JavaCompile) {
        sourceCompatibility = 1.7
        targetCompatibility = 1.7
    }

}

【讨论】:

  • 从 Studio 2.1 升级到 2.2 时遇到了这个问题,使用非 android Jars,这就是答案。
  • 这是我的 build.gradle 的样子,但它不适用于 allprojects { repositories { jcenter() } tasks.withType(JavaCompile) { sourceCompatibility = 1.7 targetCompatibility = 1.7 } }
  • 对我来说,这最终奏效了。如果您有其他也会引发此错误的依赖项,这似乎是最好的解决方案。
【解决方案2】:

如果我没有弄错 gradle android plugin extends 'java' plugin,那么你可以在 build.gradle 的“android”块中添加这两行:

apply plugin: 'com.android.application'

android {

    targetCompatibility = '1.7'
    sourceCompatibility = '1.7'

    ...
}

对我来说工作得很好。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-13
    • 1970-01-01
    • 2018-06-12
    相关资源
    最近更新 更多