【问题标题】:Duplicate class in build.gradle filebuild.gradle 文件中的重复类
【发布时间】:2021-09-23 06:33:16
【问题描述】:

我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。我在 build.gradle 文件中包含了以下依赖项。我收到以下错误。如何修复它们。

build.gradle:

plugins {
    id 'com.android.application'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"
    useLibrary  'org.apache.http.legacy'



    defaultConfig {
        applicationId "com.example.testimageuploadhttp"
        minSdkVersion 21
        targetSdkVersion 30
        versionCode 1
        versionName "1.0"

        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

}

def butterKnifeVersion = "8.4.0"
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "com.jakewharton:butterknife:${butterKnifeVersion}"
    annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"
    implementation 'androidx.appcompat:appcompat:1.2.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    implementation 'androidx.annotation:annotation:1.0.0'

    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:4.10'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
    //implementation fileTree(dir: 'libs', include: ['*.jar'])
    testImplementation 'junit:junit:4.12'
    //noinspection DuplicatePlatformClasses,DuplicatePlatformClasses
    implementation 'com.googlecode.json-simple:json-simple:1.1.1'


    //Volley Library - You need to add this line
    implementation 'com.mcxiaoke.volley:library-aar:1.0.0'

    //Add this line
    implementation 'net.gotev:uploadservice:3.4'
    }

错误:

Duplicate class org.hamcrest.BaseDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules jetified-hamcrest-core-1.1 (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10 (junit:junit:4.10)

Go to the documentation to learn how to Fix dependency resolution errors.

testImplementation 'junit:junit:4.+'
testImplementation 'junit:junit:4.12'

是重复的,但不是因为这个。我尝试注释掉 1。只有当我添加时才会发生这种情况

implementation 'com.googlecode.json-simple:json-simple:1.1.1'

其他东西编译得很好。

【问题讨论】:

  • testImplementation 'junit:junit:4.12' 和 testImplementation 'junit:junit:4.+' 应该是一样的吧?

标签: android


【解决方案1】:

问题是 org.hamcrest:hamcrest-core: 类也捆绑在 Junit 中。所以要解决问题follow these 步骤:---->

----> 1) 点击构建并清理项目 clean project

----> 2) 在buid.gradle中添加代码

configurations.all {
    resolutionStrategy.dependencySubstitution {
        substitute module('org.hamcrest:hamcrest-core:1.1') with module('junit:junit:4.10')
    }
}

所以任何人都可以解决同样的问题,但不能排除 JUnit。 那么解决方案非常简单但很奇怪

【讨论】:

    【解决方案2】:

    您已经复制了依赖项。条目:

    testImplementation 'junit:junit:4.+'
    testImplementation 'junit:junit:4.12'
    

    指向同一个库

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-01
      • 2016-12-28
      相关资源
      最近更新 更多