如何在lib中找到重复的类

时间:2019-05-03 07:59:50

标签: android gradle android-gradle

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

工作人员提出了1个异常:java.lang.RuntimeException:     java.lang.RuntimeException:     在模块classes.jar(android.arch.core:core:1.0.0-alpha1)和classes.jar(android.arch.core:runtime:1.1.1)中找到重复的android.arch.core.executor.DefaultTaskExecutor类br />     在模块classes.jar(android.arch.core:core:1.0.0-alpha1)和classes.jar(android.arch.core:runtime:1.1.1)中找到重复的android.arch.core.executor.TaskExecutor类/ strong>

我如何找到并修复哪些lib在项目中使用重复类?

app.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'
}

lib-zxing

 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'
}

3 个答案:

答案 0 :(得分:2)

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

./gradlew -q dependencies app:dependencies --configuration compile

然后像滑行一样排除旧的弓形罐子,但要正确排除,例如:

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

答案 1 :(得分:1)

尝试使用此插件,

https://github.com/KeepSafe/dexcount-gradle-plugin

它将帮助您了解库及其隐藏的依赖项。

答案 2 :(得分:1)

您可以在各处使用“搜索”对话框(两次按下Shift键打开的对话框)。

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