Android 如何查找导致类重复的依赖项?

Android 如何查找导致类重复的依赖项?,android,gradle,Android,Gradle,当我构建android项目时,它显示“复制类”异常 1 exception was raised by workers: java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class android.arch.core.executor.DefaultTaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) a

当我构建android项目时,它显示“复制类”异常

1 exception was raised by workers:   java.lang.RuntimeException:
java.lang.RuntimeException:
Duplicate class android.arch.core.executor.DefaultTaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar(android.arch.core:runtime:1.1.1)   
Duplicate class android.arch.core.executor.TaskExecutor found in modules classes.jar (android.arch.core:core:1.0.0-alpha1) and classes.jar (android.arch.core:runtime:1.1.1)**
如何在我的项目中找到并修复使用重复类的库

应用程序:Gradle

android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’

defaultConfig {
     minSdkVersion 18
    targetSdkVersion 28

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    multiDexEnabled true

    javaCompileOptions {
        annotationProcessorOptions {
            arguments = ["room.schemaLocation": "$projectDir/schemas".toString()]
        }
    }

}
dependencies {
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.9'
implementation fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

implementation ’org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.3.31’api('com.google.maps:google-maps-services:0.9.3') {
    exclude group: 'com.google.code.findbugs', module: 'jsr305'
}
implementation 'com.android.support:appcompat-v7:28.0.0’
implementation 'com.android.support:design:28.0.0'
implementation 'com.google.android.exoplayer:exoplayer:2.8.2’
implementation 'android.arch.persistence.room:runtime:1.0.0-alpha1' 
annotationProcessor 'android.arch.persistence.room:compiler:1.0.0-alpha1' 
implementation 'com.jakewharton.rxbinding:rxbinding:1.0.1'
implementation 'com.google.android.gms:play-services-maps:16.1.0'
implementation 'com.google.android.gms:play-services-location:16.0.0'
implementation 'com.google.android.gms:play-services-analytics:16.0.8'
implementation 'com.google.android.gms:play-services-places:16.1.0'

implementation 'com.google.maps.android:android-maps-utils:0.5'

implementation 'com.google.firebase:firebase-messaging:17.6.0'
implementation 'com.google.firebase:firebase-core:16.0.8'
implementation 'com.google.firebase:firebase-auth:16.2.1'
implementation 'com.facebook.android:facebook-android-sdk:5.0.0'
implementation 'com.android.support:multidex:1.0.3'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.14.1'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'io.reactivex:rxandroid:1.2.1'
implementation 'io.reactivex:rxjava:1.3.8'
implementation 'com.artemzin.rxjava:proguard-rules:1.3.3.0'
implementation 'com.google.code.gson:gson:2.8.5'
implementation 'org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.2.1'
implementation 'org.eclipse.paho:org.eclipse.paho.android.service:1.1.1'
implementation 'de.hdodenhof:circleimageview:3.0.0'
implementation ('com.github.bumptech.glide:glide:4.9.0') {
    exclude group: "com.android.support"
}
annotationProcessor 'com.github.bumptech.glide:compiler:4.9.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.10.11'
implementation project(':lib-zxing')
implementation 'com.googlecode.mp4parser:isoparser:1.1.22'
implementation 'com.github.lassana:continuous-audiorecorder:1.3.1'
implementation 'me.leolin:ShortcutBadger:1.1.22@aar'
implementation 'com.timehop.stickyheadersrecyclerview:library:0.4.3'
implementation 'org.jsoup:jsoup:1.11.3'
testImplementation 'junit:junit:4.13-beta-2'
}
李中兴

 android {
compileSdkVersion 28
buildToolsVersion ’28.0.3’

defaultConfig {
    minSdkVersion 14
    targetSdkVersion 28

    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}dependencies {
api fileTree(include: ['*.jar'], dir: 'libs')
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})

implementation 'com.android.support:appcompat-v7:28.0.0’
testImplementation 'junit:junit:4.13-beta-2'
}

您需要排除arch Jar。首先检查复制品的来源。如果使用gradle任务打印依赖关系树,则可以看到它:

./gradlew -q dependencies app:dependencies --configuration compile
然后像处理glide一样排除旧的arch Jar,但使用正确的排除方法,例如:

implementation ('android.arch.persistence.room:runtime:1.0.0-alpha1') {
    exclude group: "android.arch.core"
}

您需要排除arch Jar。首先检查复制品的来源。如果使用gradle任务打印依赖关系树,则可以看到它:

./gradlew -q dependencies app:dependencies --configuration compile
然后像处理glide一样排除旧的arch Jar,但使用正确的排除方法,例如:

implementation ('android.arch.persistence.room:runtime:1.0.0-alpha1') {
    exclude group: "android.arch.core"
}

可以使用“到处搜索”对话框(按shift键两次打开的对话框)


只需复制类名并粘贴到搜索对话框中,它就会在下拉列表中显示结果。您可以浏览结果并检查重复条目,类的完整路径将显示在类名旁边,以便您可以找到相关库,并可以安全地将其从库中的任何一个库中排除。

您可以使用“到处搜索”对话框(按shift键两次打开的对话框)


只需复制类名并粘贴到搜索对话框中,它就会在下拉列表中显示结果。您可以浏览结果并检查重复条目,类的完整路径将显示在类名旁边,这样您可以找到相关库,并可以安全地将其从库中的任何一个库中排除。

这使我避免了重复的android.arch.core异常,但它仍然复制了模块core-3.3.0.jar(com.google.zxing:core:3.3.0)和core_3.0.1.jar(core_3.0.1.jar)中的com.google.zxing.BarcodeFormat类,以及模块core-3.3.0.jar(com.google.zxing:core:3.3.0)和core_3.0.1.jar(core_3.0.1.jar)中的com.google.zxing.zxing.Binarizer类,如何修复此异常?它看起来像另一个重复的依赖项。尝试相同的方法,如我的答案中所示,但对于zxing.core。此外,你还必须处理你的依赖关系。您可以在alpha版本中包含room,但room也可以作为更新的v2.0版本提供。如果你想使用条形码扫描仪(zxing)。你可以使用这个:它使我避免了重复的android.arch.core异常,但它仍然重复了在模块core-3.3.0.jar(com.google.zxing:core:3.3.0)和core_3.0.1.jar(core_3.0.1.jar)中找到的类com.google.zxing.BarcodeFormat(com.google.zxing:core:3.3.0.0)和core_3.0.1.jar(core_3.0.1.jar),我如何修复这个异常?它看起来像是另一个重复的依赖项。尝试相同的方法,如我的答案中所示,但对于zxing.core。此外,你还必须处理你的依赖关系。您可以在alpha版本中包含room,但room也可以作为更新的v2.0版本提供。如果你想使用条形码扫描仪(zxing)。你可以用这个:我在外部找到它,但我不知道它是什么库的父库,有可能找到它并让我排除它吗?它会在右边显示模块名,通过检查模块名你可以识别它属于哪个库我在外部找到它,但我不知道它是什么库的父库,是否有可能找到它并让我排除它?它将在右侧显示模块名称,通过检查模块名称,您可以识别它属于哪个库