【问题标题】:How do I resolve "unsupported class file version 52.0" error in Android Studio 2.2.3如何解决 Android Studio 2.2.3 中的“不支持的类文件版本 52.0”错误
【发布时间】:2017-01-15 18:39:41
【问题描述】:

Internet 似乎认为问题出在 [source&target]Compatibility 字段不是 1.7,但我更改了它,无论我做什么似乎都无法消除错误。

从导入的 Eclipse 项目在 Windows 10 上运行 Android Studio 2.2.3。我的配置是:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '25.0.2'

    defaultConfig {
        applicationId "com.stuff.MyApp"
        minSdkVersion 23
        targetSdkVersion 25
    }

    buildTypes {
        release {
            minifyEnabled true
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-project.txt', 'proguard-google-api-client.txt'
        }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    }
}

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    compile 'com.android.support:support-v13:25.1.0'
    compile 'com.google.http-client:google-http-client-gson:1.22.0'
    compile 'com.google.code.gson:gson:2.8.0'
    compile 'com.google.guava:guava:21.0'
    compile 'com.google.android.gms:play-services:10.0.1'
    compile 'com.google.apis:google-api-services-drive:v2-rev249-1.22.0'
    compile 'org.jsoup:jsoup:1.10.2'
    compile 'org.apache.commons:commons-lang3:3.5'
    compile 'org.apache.commons:commons-collections4:4.1'
    compile 'com.google.api-client:google-api-client-jackson2:1.22.0'
    compile 'com.google.http-client:google-http-client:1.22.0'
    compile('com.google.api-client:google-api-client-android:1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
    compile('com.google.apis:google-api-services-sheets:v4-rev40-1.22.0') {
        exclude group: 'org.apache.httpcomponents'
    }
}

从 build-Make Project 或 build.gradle 同步似乎可以正常构建,但是当我运行或调试时,我最终得到以下错误:

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


AGPBI: {"kind":"error","text":"PARSE ERROR:","sources":[{}]}
AGPBI: {"kind":"error","text":"unsupported class file version 52.0","sources":[{}]}
AGPBI: {"kind":"error","text":"...while parsing com/google/common/annotations/Beta.class","sources":[{}]}
AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}

:app:transformClassesWithDexForDebug FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: java.lang.UnsupportedOperationException

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

BUILD FAILED

我什至尝试为 gradle JVM 增加 RAM,但我的 eclipse 项目似乎没有 gradle.properties 文件,只有一个 gradle-wrapper.properties 和 local.properties。我是 Android Studio 和 Gradle 的新手,如果这很明显,我很抱歉。

项目 build.gradle 中包含以下内容:

dependencies {
        classpath 'com.android.tools.build:gradle:2.2.3'
}

对此也有点困惑,但这似乎是正确的插件版本与 Android Studio 使用的 2.14.1 版本。对这些差异有些困惑,但请弄清楚它的有用信息。

有什么想法吗?

【问题讨论】:

    标签: android android-studio gradle build.gradle


    【解决方案1】:

    这意味着您在 IDE 项目中配置的 java SDK 版本落后于用于编译类路径上的一些库的 SDK。只需配置正确的(我会选择 1.8)

    【讨论】:

    • 我尝试将兼容性更改为 1.8 并添加对 Jake 的支持,但这只会导致 Lambdas 的 Java 代码出错
    • 如果不支持 lambdas,你的 JDK 不是 1.8 你必须调整为 JDK 版本,以及源代码级别。
    • 这与使用 Jake 有关,这是在 Android Studio 中定位 1.8 的要求。试一试,而不是做出不正确的陈述。另外,请查看code.google.com/p/android/issues/detail?id=211386 了解为什么我必须坚持使用 1.7。
    【解决方案2】:

    我有类似的问题。但我的 compileOptions 是

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    

    错误信息和你的一样

    AGPBI: {"kind":"error","text":"PARSE ERROR:","sources":[{}]}
    AGPBI: {"kind":"error","text":"unsupported class file version     52.0","sources":[{}]}
    AGPBI: {"kind":"error","text":"...while parsing     com/google/common/annotations/Beta.class","sources":[{}]}
    AGPBI: {"kind":"error","text":"1 error; aborting","sources":[{}]}
    

    并且说的错误发生在配对com/google/common/annotations/Beta.class

    我发现Beta.class属于compile 'com.google.guava:guava:21.0'

    所以我删除了番石榴的使用,错误就消失了。 希望这会对你有所帮助。

    【讨论】:

      猜你喜欢
      • 2017-12-09
      • 2016-12-28
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      相关资源
      最近更新 更多