【问题标题】:Android Studio Error:Class android.support.v4.hardware.display.DisplayManagerCompat has already been added to output. Please remove duplicate copiesAndroid Studio 错误:类 android.support.v4.hardware.display.DisplayManagerCompat 已添加到输出。请删除重复的副本
【发布时间】:2015-07-12 06:47:21
【问题描述】:

我在尝试使用 Android Studio 构建我的 android 项目时遇到以下异常

Error:Class android.support.v4.hardware.display.DisplayManagerCompat has already been added to output. Please remove duplicate copies.

我在 StackOverflow 上尝试了不同的建议,例如排除下面的包,但它仍然相同:

dependencies {
    dependencies {
        //compile project(':android-beacon-library')
        compile 'org.altbeacon:android-beacon-library:2+@aar'
        compile 'com.squareup.okhttp:okhttp:2.1.0'
        compile ('com.squareup.picasso:picasso:2.2.0') {
            exclude group: 'android.support', module: 'library'
        }
        compile 'com.google.code.gson:gson:2.2.4'
        compile('com.github.Comcast:FreeFlow:v-0.6') {
            exclude group: 'android.support', module: 'library'
        }
    }
}

使用 gradlew.bat 命令我尝试查找重复的条目,但在命令的输出中它不存在,下面粘贴的是 gradlew.bat :app:dependencies 的输出:

------------------------------------------------------------
Project :app
------------------------------------------------------------

_debugApk - ## Internal use, do not manually configure ##
+--- org.altbeacon:android-beacon-library:2+ -> 2.3.3
+--- com.squareup.okhttp:okhttp:2.1.0
|    \--- com.squareup.okio:okio:1.0.1
+--- com.squareup.picasso:picasso:2.2.0
+--- com.google.code.gson:gson:2.2.4
\--- com.github.Comcast:FreeFlow:v-0.6
     \--- com.android.support:support-v4:22.1.0
          \--- com.android.support:support-annotations:22.1.0

_debugCompile - ## Internal use, do not manually configure ##
+--- org.altbeacon:android-beacon-library:2+ -> 2.3.3
+--- com.squareup.okhttp:okhttp:2.1.0
|    \--- com.squareup.okio:okio:1.0.1
+--- com.squareup.picasso:picasso:2.2.0
+--- com.google.code.gson:gson:2.2.4
\--- com.github.Comcast:FreeFlow:v-0.6
     \--- com.android.support:support-v4:22.1.0
          \--- com.android.support:support-annotations:22.1.0

_debugTestApk - ## Internal use, do not manually configure ##
No dependencies

_debugTestCompile - ## Internal use, do not manually configure ##
No dependencies

_releaseApk - ## Internal use, do not manually configure ##
+--- org.altbeacon:android-beacon-library:2+ -> 2.3.3
+--- com.squareup.okhttp:okhttp:2.1.0
|    \--- com.squareup.okio:okio:1.0.1
+--- com.squareup.picasso:picasso:2.2.0
+--- com.google.code.gson:gson:2.2.4
\--- com.github.Comcast:FreeFlow:v-0.6
     \--- com.android.support:support-v4:22.1.0
          \--- com.android.support:support-annotations:22.1.0

_releaseCompile - ## Internal use, do not manually configure ##
+--- org.altbeacon:android-beacon-library:2+ -> 2.3.3
+--- com.squareup.okhttp:okhttp:2.1.0
|    \--- com.squareup.okio:okio:1.0.1
+--- com.squareup.picasso:picasso:2.2.0
+--- com.google.code.gson:gson:2.2.4
\--- com.github.Comcast:FreeFlow:v-0.6
     \--- com.android.support:support-v4:22.1.0
          \--- com.android.support:support-annotations:22.1.0

androidJacocoAgent - The Jacoco agent to use to get coverage data.
\--- org.jacoco:org.jacoco.agent:0.7.1.201405082137

androidJacocoAnt - The Jacoco ant tasks to use to get execute Gradle tasks.
\--- org.jacoco:org.jacoco.ant:0.7.1.201405082137
     +--- org.jacoco:org.jacoco.core:0.7.1.201405082137
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     +--- org.jacoco:org.jacoco.report:0.7.1.201405082137
     |    +--- org.jacoco:org.jacoco.core:0.7.1.201405082137 (*)
     |    \--- org.ow2.asm:asm-debug-all:5.0.1
     \--- org.jacoco:org.jacoco.agent:0.7.1.201405082137

androidTestApk - Classpath packaged with the compiled 'androidTest' classes.
No dependencies

androidTestCompile - Classpath for compiling the androidTest sources.
No dependencies

androidTestProvided - Classpath for only compiling the androidTest sources.
No dependencies

androidTestWearApp - Link to a wear app to embed for object 'androidTest'.
No dependencies

apk - Classpath packaged with the compiled 'main' classes.
No dependencies

archives - Configuration for archive artifacts.
No dependencies

compile - Classpath for compiling the main sources.
+--- org.altbeacon:android-beacon-library:2+ -> 2.3.3
+--- com.squareup.okhttp:okhttp:2.1.0
|    \--- com.squareup.okio:okio:1.0.1
+--- com.squareup.picasso:picasso:2.2.0
+--- com.google.code.gson:gson:2.2.4
\--- com.github.Comcast:FreeFlow:v-0.6
     \--- com.android.support:support-v4:22.1.0
          \--- com.android.support:support-annotations:22.1.0

debugApk - Classpath packaged with the compiled 'debug' classes.
No dependencies

debugCompile - Classpath for compiling the debug sources.
No dependencies

debugProvided - Classpath for only compiling the debug sources.
No dependencies

debugWearApp - Link to a wear app to embed for object 'debug'.
No dependencies

default - Configuration for default artifacts.
No dependencies

provided - Classpath for only compiling the main sources.
No dependencies

releaseApk - Classpath packaged with the compiled 'release' classes.
No dependencies

releaseCompile - Classpath for compiling the release sources.
No dependencies

releaseProvided - Classpath for only compiling the release sources.
No dependencies

releaseWearApp - Link to a wear app to embed for object 'release'.
No dependencies

wearApp - Link to a wear app to embed for object 'main'.
No dependencies

BUILD SUCCESSFUL

Total time: 9.674 secs

【问题讨论】:

  • 使用 --info 或 --debug 选项运行 Gradle 以找出原因。当您在两个不同的目录中具有相同的文件名时(即在主源代码中以及在测试源代码/测试 IT 源代码等的某个位置),通常会发生这种情况。我还发现,如果您生成了 .class 文件,但您在项目中没有 .java 文件但您在运行中创建了它们(例如:在 JIBX/XSL 等操作期间创建),则可能会发生这种情况

标签: java android android-studio android-gradle-plugin


【解决方案1】:

您好,将此添加到您的 gradle 文件中。它对我来说很好。希望对您有所帮助! :)

compile ('com.android.support:palette-v7:21.0.0'){
    exclude module: 'support-v4'
}

【讨论】:

  • 在依赖项之前添加此代码:配置 { all*.exclude group: 'com.android.support.v4', module: 'support-v4' } 并让我知道它是否有效。跨度>
猜你喜欢
  • 2015-08-09
  • 1970-01-01
  • 1970-01-01
  • 2015-02-12
  • 2015-10-04
  • 1970-01-01
  • 1970-01-01
  • 2023-03-15
  • 1970-01-01
相关资源
最近更新 更多