错误:程序类型已存在:org.hamcrest.CoreMatchers



当我构建我的应用程序时,我收到以下错误:程序类型已经存在:org.hamcrest.CoreMatchers。 凌晨 1:30 Gradle 同步失败(6 秒 290 毫秒(

这是我的build.gradle文件:

apply plugin: 'com.android.application'
android {
compileSdkVersion 28
defaultConfig {
applicationId "com.ercess.ercess_app"
minSdkVersion 17
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.squareup.picasso:picasso:2.71828'
implementation group: 'com.android.support', name: 'design', version: '28.0.0-rc01'
implementation 'com.basgeekball:awesome-validation:4.2'
implementation 'org.apache.httpcomponents:httpclient:4.4-alpha1'
implementation group: 'com.googlecode.json-simple', name: 'json-simple', version: '1.1.1'
}

您从 D8 收到此错误,因为运行时类路径包含 org.hamcrest.CoreMatchers 的多个定义。

关于如何解决它,请查看问题跟踪器上的答案:https://issuetracker.google.com/issues/77499230

在 Android Studio 中同步您的项目,转到导航 -> 类,确保选中"包括非项目类"复选框,然后键入"org.intellij.lang.annotations.Identifier"。Android Studio 应该会显示包含此类型的 jar。如果您熟悉排除传递依赖项,则排除包含 org.intellij.lang.annotations.Identifier 的 Maven 依赖项之一应该可以解决您的问题。

在您的情况下,使用 org.hamcrest.CoreMatchers 代替 org.intellij.lang.annotations.Identifier。

最新更新