Android Studio Gradle构建错误类型代码82



我对Kotlin和Android Studio相当陌生。当我试图向我的Android应用程序添加依赖项时(依赖项是json简单的(,它向我抛出了一个错误,原因是Invalid type code: 82。Gradle在没有任何警告和错误的情况下正确同步,但当我尝试运行代码时,它会给我带来这个错误。有人能告诉我如何解决这个问题吗?堆叠道是:-

Executing tasks: [:app:assembleDebug] in project D:PathToProj
> Task :app:preBuild UP-TO-DATE
> Task :app:preDebugBuild UP-TO-DATE
> Task :app:compileDebugAidl NO-SOURCE
> Task :app:compileDebugRenderscript NO-SOURCE
> Task :app:generateDebugBuildConfig UP-TO-DATE
> Task :app:generateDebugResValues UP-TO-DATE
> Task :app:generateDebugResources UP-TO-DATE
> Task :app:mergeDebugResources UP-TO-DATE
> Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
> Task :app:extractDeepLinksDebug UP-TO-DATE
> Task :app:processDebugManifest UP-TO-DATE
> Task :app:processDebugResources UP-TO-DATE
> Task :app:compileDebugKotlin
> Task :app:javaPreCompileDebug UP-TO-DATE
> Task :app:compileDebugJavaWithJavac
> Task :app:compileDebugSources
> Task :app:mergeDebugShaders UP-TO-DATE
> Task :app:compileDebugShaders NO-SOURCE
> Task :app:generateDebugAssets UP-TO-DATE
> Task :app:mergeDebugAssets UP-TO-DATE
> Task :app:processDebugJavaRes NO-SOURCE
> Task :app:checkDebugDuplicateClasses FAILED
> Task :app:mergeDebugJavaResource
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:checkDebugDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.hamcrest.BaseDescription found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.BaseMatcher found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.CoreMatchers found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Description found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Factory found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.Matcher found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.SelfDescribing found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.StringDescription found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.AllOf found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.AnyOf found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.DescribedAs found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.Is found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsAnything found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsEqual found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsInstanceOf found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNot found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsNull found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.core.IsSame found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.ArrayIterator found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValue found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)
Duplicate class org.hamcrest.internal.SelfDescribingValueIterator found in modules jetified-hamcrest-core-1.1.jar (org.hamcrest:hamcrest-core:1.1) and jetified-junit-4.10.jar (junit:junit:4.10)

Go to the documentation to learn how to <a href="d.android.com/r/tools/classpath-sync-errors">Fix dependency resolution errors</a>.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
Use '--warning-mode all' to show the individual deprecation warnings.
See https://docs.gradle.org/6.6.1/userguide/command_line_interface.html#sec:command_line_warnings
BUILD FAILED in 18s
14 actionable tasks: 4 executed, 10 up-to-date

我的build.gradle如下:-

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-android-extensions'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.techx.voiceassist"
minSdkVersion 16
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
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
sourceCompatibility=JavaVersion.VERSION_1_8
targetCompatibility=JavaVersion.VERSION_1_8
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}

我已经尝试了描述这个特定问题的所有其他解决方案。它们都不起作用(包括执行clean任务并再次运行(。我还尝试使用lintFix任务(尽管我不知道那是什么(来解决这个问题,但没有成功。

这个问题描述了一个依赖冲突——基本上,您使用的库带来了hamcrest-core的两个不同副本,Gradle不知道该使用哪一个。

在谷歌上搜索它,看起来json-simple,也是junit。我对此了解不多,但一个解决方案是添加

android {
....
configurations { compile.exclude group: "junit", module: "junit"}
....
}

(所以在android部分的某个地方添加配置块(。

老实说,我并不完全确定这一切——json-simple依赖于JUnit 4.10JUnit 4.11添加了新的Hamcrest匹配器——也许Gradle不能确定json-simple是否能与新的库一起工作。用compile排除JUnit可能会使Gradle在非测试构建期间忽略它,但我不确定它是否会影响测试。如果这个修复不起作用,而你遇到问题,我只是给你一些思考的东西!