【问题标题】:duplicate entry: android/support/annotation/ColorRes.class重复条目:android/support/annotation/ColorRes.class
【发布时间】:2016-02-22 07:09:53
【问题描述】:

我收到此错误:

Error:Execution failed for task ':mobile:packageAllDebugClassesForMultiDex'.
> java.util.zip.ZipException: duplicate entry:    android/support/annotation/ColorRes.class

我在做什么?

1-multiDexEnabled

2-添加这个:配置 { all*.exclude group: 'com.android.support', module: 'support-v4' } 并且没有工作(另一个重复输入错误)

3-一一删除依赖。不起作用或出现另一个错误

4-一一排除依赖,不起作用

screenshot

可能是什么问题?

build.gradle

apply plugin: 'com.android.application'


   dependencies
    {
        compile 'com.android.support:support-v4:22.2.1'
        compile 'com.android.support:appcompat-v7:22.2.1'
        compile 'com.android.support:cardview-v7:21.0.3'
        compile 'com.android.support:recyclerview-v7:21.0.3'
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.google.android.gms:play-services:8.3.0'
        compile 'com.google.maps.android:android-maps-utils:0.4'
        compile 'com.afollestad:material-dialogs:0.6.3.4@aar'
        compile 'com.bignerdranch.android:recyclerview-multiselect:0.1'
        compile 'com.j256.ormlite:ormlite-android:4.48'
        compile 'com.melnykov:floatingactionbutton:1.2.0'
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
        compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile files('libs/appodeal-1.13.10.jar')
        compile files('libs/applovin-6.1.4.jar')
        compile files('libs/inmobi-5.0.1.jar')
        compile files('libs/android-support-v4-22.2.1.jar')
        compile files('libs/my-target-4.1.2.jar')
        compile files('libs/yandex-metrica-android-2.00.jar')
    }

 android
 {
compileSdkVersion 22
buildToolsVersion "22.0.1"


defaultConfig
{
    minSdkVersion 15
    targetSdkVersion 22
    versionCode VERSION_MAJOR*10000000 + VERSION_MINOR*100000 +      VERSION_PATCH*1000 + VERSION_BUILD
    versionName "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}"

    // Enabling multidex support.
    multiDexEnabled true

    configurations {
        all*.exclude group: 'com.android.support', module: 'support-v4'
    }

}

【问题讨论】:

  • 不能肯定,但我猜这与在支持库中使用多个不同的版本号有关,
  • @Brucelet 谢谢,将它们全部更改为 22 但不起作用

标签: android android-studio sdk dependencies


【解决方案1】:

这可能意味着您有多个依赖项,要么实现同一个类,要么引用同一个类的不同版本(在不同的包中)。

前者可能会发生,因为您同时包含了来自 maven 的支持库: compile 'com.android.support:support-v4:22.2.1' 并从您的本地文件系统:compile files('libs/android-support-v4-22.2.1.jar')。我建议删除本地依赖项。

如果您混合使用不同的 Android 支持依赖版本,则可能会发生后者。在您的情况下,您将旧版本的 CardView 和 RecyclerView 与更新的根支持库混合: compile 'com.android.support:appcompat-v7:22.2.1' compile 'com.android.support:cardview-v7:21.0.3'

尝试让所有 com.android.support 依赖项参考 build 22.2.1。

综上所述,删除项目的本地文件 libs/android-support-v4-22.2.1.jar 并尝试将其作为 Gradle 依赖项:

dependencies
    {
        compile 'com.android.support:support-v4:22.2.1'
        compile 'com.android.support:appcompat-v7:22.2.1'
        compile 'com.android.support:cardview-v7:22.2.1'
        compile 'com.android.support:recyclerview-v7:22.2.1'
        compile 'com.android.support:multidex:1.0.1'
        compile 'com.google.android.gms:play-services:8.3.0'
        compile 'com.google.maps.android:android-maps-utils:0.4'
        compile 'com.afollestad:material-dialogs:0.6.3.4@aar'
        compile 'com.bignerdranch.android:recyclerview-multiselect:0.1'
        compile 'com.j256.ormlite:ormlite-android:4.48'
        compile 'com.melnykov:floatingactionbutton:1.2.0'
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
        compile 'se.emilsjolander:StickyScrollViewItems:1.1.0'
        compile fileTree(include: ['*.jar'], dir: 'libs')
        compile files('libs/appodeal-1.13.10.jar')
        compile files('libs/applovin-6.1.4.jar')
        compile files('libs/inmobi-5.0.1.jar')
        compile files('libs/my-target-4.1.2.jar')
        compile files('libs/yandex-metrica-android-2.00.jar')
    }

【讨论】:

  • 谢谢,当我删除 android-support-v4-22.2.1.jar 时,我收到了几个类似这样的错误: Error:(19, 31) error: package android.support.v4.view does not存在
  • 看起来你正在从你的构建中排除它。
  • 尝试删除这个:configurations { all*.exclude group: 'com.android.support', module: 'support-v4' }
【解决方案2】:

如果您不需要 support-annotations 包,您可以在您的 build.gradle 应用程序中排除它:

android{
    ...
    configurations {
        all*.exclude group: 'com.android.support', module: 'support-annotations'
    }
}

【讨论】:

    猜你喜欢
    • 2016-02-09
    • 2016-01-07
    • 2016-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多