java - 将 AppCompat v7 添加到 gradle 会在编译时产生多重错误

标签 java android dex

我添加了 AppCombatActivity v7 23。这产生了一些错误,我将它们解决了。然而,在运行应用程序时,我收到多个 dex 错误 -

com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;

到目前为止我所做的一切都不起作用 -

  1. 从 SDK 中删除注释 jar。
  2. 删除 v4 android-support-v4.jar

当我从 gradle 中删除编译语句时,代码就会编译。

这是我的 gradle -

dependencies {
    compile fileTree(dir: 'libs', include: '*.jar')
    compile 'com.github.deano2390:MaterialShowcaseView:1.0.5@aar'
    compile 'com.android.support:appcompat-v7:23.0.1'
}

PS - 即使使用 22.0.+ 编译

整个错误报告 -

    Information:Gradle tasks [:assembleDebug]
:preBuild UP-TO-DATE
:preDebugBuild UP-TO-DATE
:checkDebugManifest
:preReleaseBuild UP-TO-DATE
:prepareComAndroidSupportAppcompatV72301Library UP-TO-DATE
:prepareComAndroidSupportSupportV42301Library UP-TO-DATE
:prepareComGithubDeano2390MaterialShowcaseView105Library UP-TO-DATE
:prepareDebugDependencies
:compileDebugAidl UP-TO-DATE
:compileDebugRenderscript UP-TO-DATE
:generateDebugBuildConfig UP-TO-DATE
:generateDebugAssets UP-TO-DATE
:mergeDebugAssets UP-TO-DATE
:generateDebugResValues UP-TO-DATE
:generateDebugResources UP-TO-DATE
:mergeDebugResources UP-TO-DATE
:processDebugManifest UP-TO-DATE
:processDebugResources UP-TO-DATE
:generateDebugSources UP-TO-DATE
:processDebugJavaRes UP-TO-DATE
:compileDebugJava
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
:compileDebugNdk UP-TO-DATE
:compileDebugSources
:preDexDebug
:dexDebug
UNEXPECTED TOP-LEVEL EXCEPTION:
com.android.dex.DexException: Multiple dex files define Landroid/support/annotation/AnimRes;
    at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
    at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
    at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
    at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
    at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
    at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
    at com.android.dx.command.dexer.Main.runMonoDex(Main.java:303)
    at com.android.dx.command.dexer.Main.run(Main.java:246)
    at com.android.dx.command.dexer.Main.main(Main.java:215)
    at com.android.dx.command.Main.main(Main.java:106)
Error:Execution failed for task ':dexDebug'.
> com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_20\bin\java.exe'' finished with non-zero exit value 2
Information:BUILD FAILED
Information:Total time: 19.656 secs
Information:1 error
Information:0 warnings
Information:See complete output in console

我也运行了 gradlew。这是日志 -

Unzipping C:\Users\Sanved\.gradle\wrapper\dists\gradle-2.4-all\3i2gobhdl0fm2tosnn15g540i0\gradle-2.4-all.zip to C:\Users\Sanved\.gradle\wrapper\dists\gradle-2.4-all\3i2gobhdl0fm2tosnn15g540i0
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle/1.2.3/gradle-1.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle-core/1.2.3/gradle-core-1.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder/1.2.3/builder-1.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint/24.2.3/lint-24.2.3.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/5.1/proguard-gradle-5.1.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-parent/5.1/proguard-parent-5.1.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-model/1.2.3/builder-model-1.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/1.2.3/builder-test-api-1.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/sdklib/24.2.3/sdklib-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/sdk-common/24.2.3/sdk-common-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/common/24.2.3/common-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/24.2.3/manifest-merger-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/24.2.3/ddmlib-24.2.3.pom
Download https://repo1.maven.org/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.pom
Download https://repo1.maven.org/maven2/org/sonatype/oss/oss-parent/7/oss-parent-7.pom
Download https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.pom
Download https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm/5.0.3/asm-5.0.3.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-parent/5.0.3/asm-parent-5.0.3.pom
Download https://repo1.maven.org/maven2/org/ow2/ow2/1.3/ow2-1.3.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.pom
Download https://repo1.maven.org/maven2/com/google/code/gson/gson/2.2.4/gson-2.2.4.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/24.2.3/lint-checks-24.2.3.pom
Download https://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.4/ecj-4.4.pom
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-base/5.1/proguard-base-5.1.pom
Download https://repo1.maven.org/maven2/com/android/tools/annotations/24.2.3/annotations-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/layoutlib/layoutlib-api/24.2.3/layoutlib-api-24.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/dvlib/24.2.3/dvlib-24.2.3.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-compress/1.8.1/commons-compress-1.8.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/33/commons-parent-33.pom
Download https://repo1.maven.org/maven2/org/apache/apache/13/apache-13.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpclient/4.1.1/httpclient-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1.1/httpcomponents-client-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/project/4.1.1/project-4.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpmime/4.1/httpmime-4.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-client/4.1/httpcomponents-client-4.1.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava/17.0/guava-17.0.pom
Download https://repo1.maven.org/maven2/com/google/guava/guava-parent/17.0/guava-parent-17.0.pom
Download https://repo1.maven.org/maven2/net/sf/kxml/kxml2/2.3.0/kxml2-2.3.0.pom
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-api/24.2.3/lint-api-24.2.3.pom
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-analysis/5.0.3/asm-analysis-5.0.3.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.1/httpcore-4.1.pom
Download https://repo1.maven.org/maven2/org/apache/httpcomponents/httpcomponents-core/4.1/httpcomponents-core-4.1.pom
Download https://repo1.maven.org/maven2/commons-logging/commons-logging/1.1.1/commons-logging-1.1.1.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/5/commons-parent-5.pom
Download https://repo1.maven.org/maven2/org/apache/apache/4/apache-4.pom
Download https://repo1.maven.org/maven2/commons-codec/commons-codec/1.4/commons-codec-1.4.pom
Download https://repo1.maven.org/maven2/org/apache/commons/commons-parent/11/commons-parent-11.pom
Download https://repo1.maven.org/maven2/com/android/tools/external/lombok/lombok-ast/0.2.3/lombok-ast-0.2.3.pom
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle/1.2.3/gradle-1.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/gradle-core/1.2.3/gradle-core-1.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder/1.2.3/builder-1.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint/24.2.3/lint-24.2.3.jar
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-gradle/5.1/proguard-gradle-5.1.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-model/1.2.3/builder-model-1.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/builder-test-api/1.2.3/builder-test-api-1.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/sdklib/24.2.3/sdklib-24.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/sdk-common/24.2.3/sdk-common-24.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/common/24.2.3/common-24.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/build/manifest-merger/24.2.3/manifest-merger-24.2.3.jar
Download https://repo1.maven.org/maven2/com/android/tools/ddms/ddmlib/24.2.3/ddmlib-24.2.3.jar
Download https://repo1.maven.org/maven2/com/squareup/javawriter/2.5.0/javawriter-2.5.0.jar
Download https://repo1.maven.org/maven2/org/bouncycastle/bcpkix-jdk15on/1.48/bcpkix-jdk15on-1.48.jar
Download https://repo1.maven.org/maven2/org/bouncycastle/bcprov-jdk15on/1.48/bcprov-jdk15on-1.48.jar
Download https://repo1.maven.org/maven2/org/ow2/asm/asm/5.0.3/asm-5.0.3.jar
Download https://repo1.maven.org/maven2/org/ow2/asm/asm-tree/5.0.3/asm-tree-5.0.3.jar
Download https://repo1.maven.org/maven2/com/google/code/gson/gson/2.2.4/gson-2.2.4.jar
Download https://repo1.maven.org/maven2/com/android/tools/lint/lint-checks/24.2.3/lint-checks-24.2.3.jar
Download https://repo1.maven.org/maven2/org/eclipse/jdt/core/compiler/ecj/4.4/ecj-4.4.jar
Download https://repo1.maven.org/maven2/net/sf/proguard/proguard-base/5.1/proguard-base-5.1.jar

FAILURE: Build failed with an exception.

* What went wrong:
A problem occurred configuring root project 'AIVVA'.
> Could not resolve all dependencies for configuration ':classpath'.
   > Could not download proguard-base.jar (net.sf.proguard:proguard-base:5.1)
      > Could not get resource 'https://repo1.maven.org/maven2/net/sf/proguard/proguard-base/5.1/proguard-base-5.1.jar'.
         > Failed to move file 'C:\Users\Sanved\AppData\Local\Temp\gradle_download7702719224180984692bin' into filestore at 'C:\Users\Sanved\.gradle\caches\modules-2\files-2.1\net.sf.proguard\proguard-base\5.1\dc606dd778fe4685be16d5a171782ccfe0ef5637\proguard-base-5.1.jar'

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 10 mins 0.155 secs

最佳答案

您可以使用以下命令来检查项目的依赖关系。 ./gradlew youtProjectName:依赖项

此命令告诉您哪个是您的依赖关系树,这对于您的情况很有用,可以了解哪些依赖关系正在重复。您的 libs 文件夹中也可能有一些重复的依赖项

关于java - 将 AppCompat v7 添加到 gradle 会在编译时产生多重错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32934788/

相关文章:

java - 序列化有什么用?

java.io.IOException : Server returned HTTP response code: 500 for URL

java - 堆栈、队列和链表脑筋急转弯的输出

java - 为什么我没有操作的对象在Java中发生了变化?

android - 使用 Google Play 服务时如何避免 65k 方法限制

java - 使用我自己安装的Android应用程序完全反汇编APK文件

android - "This method is deprecated"对应用程序开发人员意味着什么

Android ImageView 在 GingerBread 下面的 FrameLayout 中不匹配_parent

android - 从 Android 应用程序创建输出文档

android - 多次定义BuildConfig,Gradle Test Build报错