You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Android Studio中Duplicate Runnable错误求助:重复类问题

解决Android Studio中AutoAnnotation重复类错误

错误信息

Caused by:
org.gradle.workers.internal.DefaultWorkerExecutor$WorkExecutionException: A failure occurred while executing com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable
Caused by: java.lang.RuntimeException: Duplicate class com.google.auto.value.AutoAnnotation found in modules auto-value-1.5.3 (com.google.auto.value:auto-value:1.5.3) and auto-value-annotations-1.6.3 (com.google.auto.value:auto-value-annotations:1.6.3)

我的build.gradle.kts(:app)配置

plugins {
    id("com.android.application")
    id("com.google.gms.google-services")
}

android {
    namespace = "com.s22010151.parkspotterapp"
    compileSdk = 34

    defaultConfig {
        applicationId = "com.s22010151.parkspotterapp"
        minSdk = 24
        targetSdk = 34
        versionCode = 1
        versionName = "1.0"
        testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            isMinifyEnabled = false
            proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
        }
    }
    buildFeatures {
        viewBinding = true
    }
    compileOptions {
        sourceCompatibility = JavaVersion.VERSION_1_8
        targetCompatibility = JavaVersion.VERSION_1_8
    }

    // Other configurations
    // configurations {
    //     cleanedAnnotations
    //     compile.exclude group: 'org.jetbrains' , module:'annotations'
    //     api.exclude group: 'org.jetbrains' , module:'annotations'
    //     implementation.exclude group: 'org.jetbrains' , module:'annotations'
    // }
}

dependencies {
    //implementation ("com.google.auto.value:auto-value:1.5.3")
    // implementation ("com.github.Inconnu08:android-ratingreviews:1.2.0")
    // {
    //     exclude group: 'org.jetbrains', module: 'annotations'
    // }
    implementation("androidx.appcompat:appcompat:1.7.0")
    implementation("com.google.android.material:material:1.12.0")
    implementation("androidx.constraintlayout:constraintlayout:2.1.4")
    implementation("com.google.firebase:firebase-auth:23.0.0")
    implementation("com.google.firebase:firebase-database:21.0.0")
    implementation ("com.firebaseui:firebase-ui-database:8.0.2")
    implementation("com.google.firebase:firebase-storage:21.0.0")
    implementation("com.google.firebase:firebase-messaging:24.0.0")
    //annotationProcessor ("androidx.room:room-compiler:2.4.0-beta01")
    implementation ("androidx.room:room-compiler-processing-testing:2.6.1")
    testImplementation("junit:junit:4.13.2")
    implementation ("com.github.bumptech.glide:glide:4.14.2")
    annotationProcessor ("com.github.bumptech.glide:compiler:4.14.2")
    implementation ("de.hdodenhof:circleimageview:3.1.0")
    implementation ("androidx.recyclerview:recyclerview:1.3.2")
    testImplementation("org.junit.jupiter:junit-jupiter:5.8.1")
    androidTestImplementation("androidx.test.ext:junit:1.2.1")
    androidTestImplementation("androidx.test.espresso:espresso-core:3.6.1")
    implementation("com.google.android.gms:play-services-maps:19.0.0")
    implementation("com.google.android.gms:play-services-location:21.3.0")
    implementation("com.karumi:dexter:6.2.1")
    implementation ("androidx.cardview:cardview:1.0.0")
    implementation("com.github.clans:fab:1.6.4")

    configurations.implementation{
        exclude("org.jetbrains", "annotations")
    }
    configurations.api{
        exclude("org.jetbrains" , "annotations")
    }
    configurations.compileOnly{
        exclude("org.jetbrains" , "annotations")
    }

    // implementation ("com.google.auto.value:auto-value:1.6.3")
    // annotationProcessor ("com.google.auto.value:auto-value:1.6.3")
}

已尝试的无效方法

  • 排除org.jetbrains的annotations依赖
  • 清理Gradle缓存
  • 清理并重新构建项目

修复方案

1. 定位冲突来源

在Android Studio的终端执行命令,查看完整依赖树:

./gradlew app:dependencies

搜索auto-value关键词,找到引入auto-value-1.5.3的间接依赖(大概率是com.firebaseui:firebase-ui-database或androidx.room相关依赖)。

2. 排除冲突依赖

找到来源后,在对应的依赖项中排除旧版本的auto-value:
比如如果是firebase-ui-database引入的,修改依赖配置如下:

implementation("com.firebaseui:firebase-ui-database:8.0.2") {
    exclude(group = "com.google.auto.value", module = "auto-value")
}

3. 强制统一版本(可选)

如果不想逐个排查依赖,可在android代码块外添加版本强制策略,让所有依赖统一使用指定版本的auto-value:

configurations.all {
    resolutionStrategy {
        force("com.google.auto.value:auto-value:1.6.3")
        force("com.google.auto.value:auto-value-annotations:1.6.3")
    }
}

4. 重新构建项目

执行Clean Project -> Rebuild Project,或在终端运行命令:

./gradlew clean build

内容的提问来源于stack exchange,提问作者Jude Shaveen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 20:33:16