在模块 classes.jar 中发现重复的类

新手上路,请多包涵

使用 Cxense SDK for Android” ,我收到重复类的消息:

 Duplicate class android.support.v4.app.INotificationSideChannel found in modules classes.jar (**com.android.support:support-compat:27.1.1**) and classes.jar (**com.android.support:support-v4:22.2.0**)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules classes.jar (com.android.support:support-compat:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules classes.jar (com.android.support:support-compat:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment$1 found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.ListFragment$2 found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)
Duplicate class android.support.v4.app.LoaderManager found in modules classes.jar (com.android.support:support-fragment:27.1.1) and classes.jar (com.android.support:support-v4:22.2.0)

这是我的应用程序级 build.gradle 配置:

 apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    defaultConfig {
        applicationId "com.tototita.cxensetestapp"
        minSdkVersion 15
        targetSdkVersion 27
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }

    packagingOptions {
        exclude 'META-INF/LICENSE'
    }
    compileOptions {
        sourceCompatibility = '1.8'
        targetCompatibility = '1.8'
    }

}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    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'

     //**CXsense
     implementation 'com.cxpublic:cxense-android:1.0.1'
}

我怎样才能避免这种肯定包含在 Cxense SDK 中的重复类?

原文由 Jorgesys 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 1k
2 个回答

如果有重复,使用 exclude

 implementation ('com.cxpublic:cxense-android:1.0.1') {
    exclude group: "com.android.support", module: "support-v4"
}

或者删除 implementation 'com.android.support:appcompat-v7:27.1.1' 以支持 support-v4

请参阅: https ://discuss.gradle.org/t/how-do-i-exclude-specific-transitive-dependencies-of-something-i-depend-on/17991

原文由 aucd29 发布,翻译遵循 CC BY-SA 4.0 许可协议

有两种方法可以解决您的问题。

  1. 排除 重复依赖 while implementation 分别

  2. 通用方式 从每个 implementation 中排除 重复的依赖 项。

让我们首先了解问题:

在这里,在您的案例中,工件 com.android.support 是重复的,因为您的 应用程序模块 使用版本: 27.1.1 而您的工件 com.cxpublic:cxense-android:1.0.1 具有内部依赖性 com.android.support 使用版本: 22.2.0

因此,您应该手动删除其中一个 (建议删除旧版本或低版本) 。让我们尝试删除它!


通过第一种方法:

 implementation ('com.cxpublic:cxense-android:1.0.1') {
    exclude group: "com.android.support", module: "support-v4"
}

排除 com.android.support 放入我们的工件 com.cxpublic:cxense-android:1.0.1 将不会导入 support-v4 库 当我们在这个工件上使用我们的实现时

因此,可以通过手动将此块放置到每个有此冲突的工件来解决问题。

通过第二种方式:

我们可以删除 包含的依赖 项并将它们替换为一个具有最新编号的包。在我们的例子中,它是 support-v4 不同的版本。因此,转到应用程序级别 build.gradle 的 android 块并将其放在块下方以从所有工件中删除重复的 support-v4 ,这样我们就可以拥有不同的依赖性。

 android {
    // Some other stuffs
    configurations {
        all*.exclude module: 'support-v4' // This removes all other versions of `support-v4` if gets duplicated from all the artifacts.
    }
    // Rest of other stuffs
}

原文由 Jeel Vankhede 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题