Android Studio 错误:原因:androidx/room/RoomProcessor 已由较新版本的 Java 运行时(类文件版本 61.0)编译

Android Studio error: Cause: androidx/room/RoomProcessor has been compiled by a more recent version of the Java Runtime (class file version 61.0)

提问人:tmschaaf 提问时间:11/12/2023 更新时间:11/12/2023 访问量:44

问:

原因:androidx/room/RoomProcessor 已由较新版本的 Java 运行时(类文件版本 61.0)编译,此版本的 Java 运行时只能识别最高 55.0 的类文件版本

我正在编译的项目在 sdk 版本 26 移动设备上运行正常。现在我正在为 sdk 版本 33 重建它。

我的build.gradle:

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

buildscript {
    ext {
        // Android Gradle Project Version
        agp_version = '7.1.3'
        ///agp_version = '7.2'
    }
    repositories {
        mavenCentral()
        google()
    }
    dependencies {
        ///classpath 'com.android.tools.build:gradle:7.1.3'
        classpath "com.android.tools.build:gradle:$agp_version"
        
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

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

task clean(type: Delete) {
    delete rootProject.buildDir
}

我的build.gradle(:app):

apply plugin: 'com.android.application'

android {
    ///compileSdkVersion 32
    compileSdkVersion 34
    defaultConfig {
        applicationId "com.tmschaaf.earthquakev"        // was: com.cis2237.schaafp7
        minSdkVersion 26
        targetSdkVersion 34
        versionCode 2
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    dataBinding.enabled = true
    compileOptions {
        ///sourceCompatibility = '1.8'
        ///targetCompatibility = '1.8'
        sourceCompatibility = JavaVersion.VERSION_11
        targetCompatibility = JavaVersion.VERSION_11

    }
///    kotlinOptions {
///        jvmTarget = '11'
///    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.6.1'
    ///implementation 'androidx.appcompat:appcompat:1.0.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test:runner:1.5.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
    implementation 'androidx.recyclerview:recyclerview:1.3.2'
    implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
    implementation 'com.google.android.material:material:1.10.0'
    implementation 'com.google.android.material:material:1.11.0-beta01'
    implementation 'androidx.coordinatorlayout:coordinatorlayout:1.3.0-alpha02'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.preference:preference:1.2.1'
    implementation 'androidx.room:room-runtime:2.6.0'
    annotationProcessor 'androidx.room:room-compiler:2.6.0'
    testImplementation 'androidx.room:room-testing:2.6.0'
    implementation 'com.google.android.gms:play-services-maps:18.2.0'
    ///implementation 'android:exported:false'
    implementation 'androidx.activity:activity-ktx:1.8.0'
}

// added 9/10/2023
allprojects {
    repositories {
        maven {
            url "https://maven.google.com"
        }
        google()
    ///    jcenter()
    ///    mavenCentral()
    }
}

从一些注释掉的行中可以看出,我尝试了几种不同的选项,包括升级到 gradle 7.2。

java android jvm build.gradle

评论


答: 暂无答案