我们有以下设置:
App>框架A>框架B 该应用使用A和B。框架A仅使用B。
这些框架是单独构建的,并通过私有Maven存储库提供服务。
我们现在对框架B进行了大量重构,包括从gson切换到moshi。
现在构建应用程序时,出现以下错误:
AGPBI: {"kind":"error","text":"Program type already present: moe.banana.jsonapi2.JsonApiConverterFactory$MoshiResponseBodyConverter","sources":[{}],"tool":"D8"}
> Task :app:transformDexArchiveWithDexMergerForApi18DevelopmentDebug FAILED
java.lang.RuntimeException: java.lang.RuntimeException: com.android.builder.dexing.DexArchiveMergerException: Error while merging dex archives: ...
Learn how to resolve the issue at https://developer.android.com/studio/build/dependencies#duplicate_classes.
框架B的依赖性相当“无聊”:
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.squareup.moshi:moshi:1.8.0'
implementation 'com.squareup.retrofit2:retrofit:2.6.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.2'
implementation "com.squareup.retrofit2:converter-moshi:2.6.0"
implementation 'moe.banana:moshi-jsonapi:3.5.0'
implementation 'moe.banana:moshi-jsonapi-retrofit-converter:3.5.0'
// optional, for retrofit
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.1.1"
}
对于框架A,它是:
dependencies {
// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.anko:anko-coroutines:$anko_version"
implementation "androidx.core:core-ktx:$ktx_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"
implementation 'androidx.annotation:annotation:1.1.0'
implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-gson:$retrofit_version"
implementation "com.squareup.okhttp3:logging-interceptor:$okhttp_version"
implementation 'com.squareup.wire:wire-runtime:2.2.0'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation "com.google.android.gms:play-services-location:$play_services_version"
implementation "FrameworkB"
}
一旦我们现在将框架A包含到应用程序中,就会抛出该异常。
$ ./gradlew app:dependencies
-> jsonapi2库只有一个条目。一切看起来都正确。尝试了几天之后,现在解决了该错误,但到了现在,我们仍然不知道如何进一步查找该错误。
还有另一种方法可以查看gradle认为这种重复的类/依赖来自何处吗?