【问题标题】:Android build error Execution failed for task ':app:checkDebugDuplicateClasses'Android构建错误任务':app:checkDebugDuplicateClasses'的执行失败
【发布时间】:2021-08-11 13:10:35
【问题描述】:

App Building error:'app:checkDebugDuplicateClasses' 我知道通过删除一个类可以解决这个错误,但我不知道如何删除它 或者有没有其他方法可以解决这个问题。

谢谢

FAILURE:构建失败并出现异常。 什么地方出了错: 任务 ':app:checkDebugDuplicateClasses' 执行失败。 执行 com.android.build.gradle.internal.tasks.CheckDuplicatesRunnable 时发生故障 在模块中发现重复的类 com.google.firebase.iid.FirebaseInstanceIdReceiver jetified-firebase-iid-21.0.1-runtime (com.google.firebase:firebase-iid:21.0.1) 和 jetified-firebase-messaging-22.0.0-runtime (com.google.firebase:firebase-messaging:22.0.0) 转到文档以了解如何 d.android.com/r/tools/classpath-sync-errors 修复依赖解析错误

  • 尝试: 使用 --stacktrace 选项运行以获取堆栈跟踪。 使用 --info 或 --debug 选项运行以获得更多日志输出。运行 --scan 以获得完整的见解。

  • 通过https://help.gradle.org获得更多帮助

在 1m 28s 内构建失败 18 个可操作的任务:18 个已执行

这是我的模块 gradle 文件

plugins {
    id 'com.android.application'
    id 'com.google.gms.google-services'

}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.example.shipelse"
        minSdkVersion 24
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"
        multiDexEnabled true


        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
        debug {
            debuggable true
            minifyEnabled true
            //useProguard true
            shrinkResources true
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
}

dependencies {

    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.navigation:navigation-fragment:2.3.5'
    implementation 'androidx.navigation:navigation-ui:2.3.5'
    implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
    implementation 'com.google.firebase:firebase-auth:21.0.1'
    implementation 'com.google.firebase:firebase-messaging:22.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'androidx.preference:preference:1.1.1'

    implementation 'androidx.core:core:1.5.0'
    implementation 'androidx.drawerlayout:drawerlayout:1.1.1'

    testImplementation 'junit:junit:4.13.2'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    implementation platform('com.google.firebase:firebase-bom:26.2.0')
    implementation 'com.google.firebase:firebase-analytics'

    implementation 'com.google.firebase:firebase-auth'
    implementation 'com.google.android.gms:play-services-location:18.0.0'

    //noinspection GradleCompatible
    implementation 'androidx.core:core:1.5.0'

    implementation "androidx.security:security-crypto:1.0.0"

    // For Identity Credential APIs
    implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
}

这是我的项目 gradle 文件

buildscript {
    repositories {
        google()
        mavenCentral()
        jcenter()
        gradlePluginPortal()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:4.2.1'
        classpath 'com.google.gms:google-services:4.3.8'
        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        google()
        mavenCentral()
        jcenter()
        maven { url "https://jitpack.io" }
        maven {
            url 'https://maven.mapmyindia.com/repository/mapmyindia/'
        }
    }
}

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

【问题讨论】:

  • 您似乎混合了 Firebase 依赖项,一些依赖 BOM 获取版本,另一些则直接在 dependencies 闭包中指定版本。这似乎不一致,它可能会导致您的问题。您是否尝试过从com.google.firebase:firebase-authcom.google.firebase:firebase-messaging 中删除版本号,以便更像您的com.google.firebase:firebase-analyticscom.google.firebase:firebase-auth

标签: android firebase android-studio build.gradle android-build


【解决方案1】:

您同时拥有 mavenCentral 和 jcenter 作为存储库。从项目 gradle 文件中删除 jcenter(),因为它已经过时了。

此外,删除您的 firebase-messaging 依赖项的版本: 实施 'com.google.firebase:firebase-messaging'

【讨论】:

    【解决方案2】:

    在 gradle.properties 文件中启用 androidX 和 Jetifier。将以下行添加到 gradle.properties 文件中:

    android.useAndroidX=true 
    android.enableJetifier=true
    

    【讨论】:

      猜你喜欢
      • 2022-10-20
      • 2019-10-05
      • 1970-01-01
      • 1970-01-01
      • 2021-10-09
      • 2017-10-19
      • 1970-01-01
      • 2018-04-09
      • 1970-01-01
      相关资源
      最近更新 更多