【问题标题】:Duplicate class error on build for Jackson pluginJackson插件构建时出现重复的类错误
【发布时间】:2019-11-21 08:57:29
【问题描述】:

打开一个我已经工作了一段时间但几个月都没有打开的项目后,我在尝试编译我的 Android 项目时遇到错误。我得到的错误可以在这里看到:

我的项目构建gradle如下:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        google()
        jcenter()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        mavenCentral()
        jcenter()
        google()
    }
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

而我的应用程序 build.gradle 依赖项如下(由于敏感数据而删除了一些元素):

apply plugin: 'com.android.application'

android {
    compileSdkVersion 27
    buildToolsVersion '28.0.2'

    defaultConfig {
        applicationId "com.x.x"
        minSdkVersion 18
        targetSdkVersion 27
        versionCode 45
        versionName "1.45.1"
    }
    packagingOptions {
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/NOTICE'
    }

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

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation files('libs/jackson-core-2.7.0.jar')
    implementation files('libs/jackson-databind-2.7.0.jar')
    implementation files('libs/jackson-annotations-2.7.0.jar')
    // for joda
    implementation 'com.android.support:appcompat-v7:27.1.1'
    implementation 'com.android.support:support-v4:27.1.1'
    implementation 'com.android.support:design:27.1.1'
    implementation 'com.google.firebase:firebase-appindexing:16.0.1'
    implementation 'com.android.support:cardview-v7:27.1.1'
    implementation 'com.google.code.gson:gson:2.8.2'
    implementation 'joda-time:joda-time:2.9.4'
    implementation 'com.google.android.exoplayer:exoplayer:r1.5.2'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
    implementation 'com.afollestad.material-dialogs:commons:0.9.6.0'
    implementation 'com.karumi:dexter:4.0.0'
    implementation 'com.scottyab:aescrypt:0.0.1'
    implementation 'com.wdullaer:materialdatetimepicker:3.4.1'
    implementation 'com.android.support.constraint:constraint-layout:1.1.3'
    implementation 'net.sourceforge.htmlcleaner:htmlcleaner:2.16'
    implementation 'io.sentry:sentry-android:1.7.5'
    testImplementation 'junit:junit:4.12'
    configurations.all {
        exclude group: 'com.android.support', module: 'support-v13'
    }
}

我试着换了

    implementation files('libs/jackson-core-2.7.0.jar')
    implementation files('libs/jackson-databind-2.7.0.jar')
    implementation files('libs/jackson-annotations-2.7.0.jar')

到更新版本(2.9.9,我手动下载后),但无济于事。该错误与上图相同,但使用 2.9.9 而不是 2.8.7。

我还尝试将 implementation files 更改为 implementation,它利用 Gradle 下载插件,但它给出了同样的错误。

我当然也尝试过清理和重建项目,但也没有任何效果。

可以在https://pastebin.com/EPUuEXTd 看到来自我的构建输出窗口的完整错误。

我在 StackOverflow 和 Github 上查看了不同的答案,但没有发现可能与我有关的问题。

【问题讨论】:

    标签: android gradle jackson


    【解决方案1】:

    所以我最终自己修复了它。当我包含 implementation 'io.sentry:sentry-android:1.7.5' 依赖项时发生错误。经过反复试验,我发现这会导致错误,因为Sentry 包含他们自己版本的Jackson 库,所以我自己包含它并通过Sentry 包含它。

    删除

        implementation files('libs/jackson-core-2.7.0.jar')
        implementation files('libs/jackson-databind-2.7.0.jar')
        implementation files('libs/jackson-annotations-2.7.0.jar')
    

    但没有解决问题,因为文件仍在项目中。我需要从项目文件夹中完全删除 3 个 .jar 文件,以使错误消失。然后我重新添加了 jackson 作为依赖实现,但这次是通过 Gradle,而不是通过文件系统,所以像这样:

        implementation 'com.fasterxml.jackson.core:jackson-core:2.9.9'
        implementation 'com.fasterxml.jackson.core:jackson-annotations:2.9.9'
        implementation 'com.fasterxml.jackson.core:jackson-databind:2.9.9'
    

    现在一切正常。请注意 - Sentry 和 Jackson 的版本号没有区别,我只是决定在我使用它的同时进行更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多