非法 class 文件:Class 模块信息缺少超类型。 Class 文件版本 53

Illegal class file: Class module-info is missing a super type. Class file version 53

当我将 firebase perf 依赖项添加到我的项目中时,出现此错误 Illegal class file: Class module-info is missing a super type. Class file version 53. 我的 Gradle 和 google 服务项目级依赖项是

    classpath 'com.android.tools.build:gradle:3.5.1'
    classpath 'com.google.gms:google-services:4.3.2'

并且我遵循了他们文档中提到的确切步骤 https://firebase.google.com/docs/perf-mon/get-started-android

我已尝试清理、重建和清除 Android Studio 缓存。

并且还尝试从 Whosebug 解决类似的问题

项目级构建gradle

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com' }

    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.1'
        classpath 'com.google.gms:google-services:4.3.2'
        classpath 'com.google.firebase:perf-plugin:1.3.1'  // Performance Monitoring plugin
    }
}

allprojects {
    repositories {
        google()
        jcenter()

    }
}

应用级构建 gradle

buildscript {
    repositories {
        maven { url 'https://maven.fabric.io/public' }
        maven { url "https://jitpack.io" }
        jcenter()

    }

    dependencies {
        classpath 'io.fabric.tools:gradle:1.31.0'
    }
}
apply plugin: 'com.android.application'
apply plugin: 'io.fabric'
// Apply the Performance Monitoring plugin to enable instrumentation
apply plugin: 'com.google.firebase.firebase-perf'

repositories {
    maven { url 'https://maven.fabric.io/public' }
    maven { url "https://jitpack.io" }
    maven {
        url 'https://maven.google.com'
    }

}
dependencies {
// Not added all dependencies , Just the firebase one SINCE ITS PRETTY LONG
implementation 'com.google.firebase:firebase-perf:19.0.0'
}

将此添加到您的应用级 build.gradle 文件可暂时解决问题

debug {
          FirebasePerformance {
            // Set this flag to 'false' to disable @AddTrace annotation processing and
            // automatic HTTP/S network request monitoring
            // for a specific build variant at compile time.
            instrumentationEnabled false
          }
        }

根据其他答案和评论进行编辑

将 gradle 插件更改为 3.6.0 以解决它,因为它已在该版本中得到修复

仅供参考,这是一个 AGP 错误...已在 AGP 3.6 中修复

将构建 Gradle 从 3.5.1 更新到 3.6.0 解决了我的问题。

另外 gradle.properties 中删除这个 如果你出于任何原因碰巧有它:

android.enableR8=false

(如果存在上述行,即使使用 com.android.tools.build:gradle:4.1.2 也会出现错误)