【问题标题】:Implementation of library giving duplicate error给出重复错误的库的实现
【发布时间】:2021-08-20 22:42:45
【问题描述】:

我试图在我的项目中实现“com.github.barteksc:android-pdf-viewer:2.8.2”并且我能够同步 gradle 文件但是当我尝试启动应用程序时它给了我这个错误

Duplicate class android.support.v4.app.INotificationSideChannel found in modules core-1.5.0-

runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.app.INotificationSideChannel$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.IResultReceiver$Stub$Proxy found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$1 found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyResultReceiver found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)
Duplicate class android.support.v4.os.ResultReceiver$MyRunnable found in modules core-1.5.0-runtime (androidx.core:core:1.5.0) and support-compat-25.3.1-runtime (com.android.support:support-compat:25.3.1)

Go to the documentation to learn how to Fix dependency resolution errors

我不明白为什么我会在下面发布我的 build.gradle

plugins {
    id 'com.android.application'
    id 'kotlin-android'
}

android {
    compileSdkVersion 30
    buildToolsVersion "30.0.3"

    defaultConfig {
        applicationId "com.jenson.resumeapp"
        minSdkVersion 19
        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 {
    implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
    implementation 'androidx.core:core-ktx:1.5.0'
    implementation 'androidx.appcompat:appcompat:1.3.0'
    implementation 'com.google.android.material:material:1.3.0'
    implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
    testImplementation 'junit:junit:4.+'
    androidTestImplementation 'androidx.test.ext:junit:1.1.2'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'

}

我似乎没有找到任何有效的方法?

【问题讨论】:

  • 可能是缓存问题,只需尝试以下 2 个简单步骤 1. 使缓存无效并重新启动,然后 2. 清理并重建项目,然后重试。
  • 试过了,还是报同样的错误

标签: android implementation


【解决方案1】:

在 gradle.properties 文件中添加这些行

android.useAndroidX = true
android.enableJetifier = true

【讨论】:

  • 我只需要添加 android.enableJetifier = true 但如果你没有另一个添加那个我会说。我已经有第一名了
【解决方案2】:

我在实施时遇到了同样的问题:

com.github.shts:StoriesProgressView:3.0.0

至少在我的情况下,问题是 StoriesProgessView 依赖项正在从 com.android.support:support-compat 检索相同的类,该类现在已经存在于 androidx 核心包中,导致冲突升级。

我是这样处理的: 通过检查 Dependency 树,我发现 StoriesProgressView 正在引入这些依赖项,为了删除这些依赖项,我将排除规则添加到依赖项中,如下所示:

implementation ('com.github.shts:StoriesProgressView:3.0.0') {
        exclude group: "com.android.support", module: "support-compat"
        exclude group: "com.android.support", module: "support-media-compat"
    }

这停止了从旧包中提取类。

但在您的情况下,似乎没有任何第三方依赖项,因此可能遵循 Malik Ali 的回答就足够了。如果没有,试试这个!

【讨论】:

    【解决方案3】:

    gradle.properties中添加这一行

    android.enableJetifier = true
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-19
      • 2017-11-09
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 1970-01-01
      • 2016-12-29
      • 2013-01-11
      相关资源
      最近更新 更多