Java 多个dex文件定义landroid/support/annotation/AnimRes

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/26342444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 02:17:31  来源:igfitidea点击:

multiple dex files define landroid/support/annotation/AnimRes

javaandroid

提问by Niklas

The moment I added the android support annotations to my dependencies

我将 android 支持注释添加到我的依赖项的那一刻

compile 'com.android.support:support-annotations:20.0.0'

compile 'com.android.support:support-annotations:20.0.0'

I got this error:

我收到此错误:

Error Code: 2 Output: 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:594) at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) at com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) at com.android.dx.command.dexer.Main.run(Main.java:230) at com.android.dx.command.dexer.Main.main(Main.java:199) at com.android.dx.command.Main.main(Main.java:103)

错误代码:2 输出:UNEXPECTED TOP-LEVEL EXCEPTION:com.android.dex.DexException:多个 dex 文件定义 Landroid/support/annotation/AnimRes;在 com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:594) 在 com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:552) 在 com.android.dx.merge.DexMerger.mergeClassDefs (DexMerger.java:533) at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:170) at com.android.dx.merge.DexMerger.merge(DexMerger.java:188) at com.android。 dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:439) 在 com.android.dx.command.dexer.Main.runMonoDex(Main.java:287) 在 com.android.dx.command.dexer.Main。在 com.android.dx.command.dexer.Main.main(Main.java:199) 处运行(Main.java:230)。

build.gradle

构建.gradle

android {
    compileSdkVersion 19
    buildToolsVersion '20.0.0'

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 19
    }
}

dependencies {
    compile 'com.android.support:support-v4:19.0.0'
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.android.support:support-annotations:20.0.0'
}

Anybody else experienced this issue? I have tried the solutions from here.

还有其他人遇到过这个问题吗?我已经尝试过这里的解决方案。

采纳答案by Mister Smith

The problem is that android-support-annotations.jarused to be a separate library containing the android annotations, but for some reason these annotations are already included in recent versions of the android-support-v4.jarfile.

问题是它android-support-annotations.jar曾经是一个包含 android 注释的单独库,但由于某种原因,这些注释已经包含在最新版本的android-support-v4.jar文件中。

Deleting the annotations jar solved the issue.

删除注释 jar 解决了这个问题。

回答by Niklas

I managed to fix this issue. The reason was that I included the android support library 19.0.0 as a dependency, but 19.1.0 is required. See here for more information

我设法解决了这个问题。原因是我包含了 android 支持库 19.0.0 作为依赖项,但 19.1.0 是必需的。浏览此处获取更多信息

So it has to be

所以它必须是

dependencies {
    compile 'com.android.support:support-v4:19.1.0'
    compile 'com.crashlytics.android:crashlytics:1.+'
    compile 'com.android.support:support-annotations:20.0.0'
}

回答by Evans Kakpovi

I deleted the android-support-v4.jar and it worked.

我删除了 android-support-v4.jar 并且它起作用了。

回答by petrsyn

If you import AppCompatas a library project and you also have android-support-annotations.jarin libs elsewhere, make sure to import everywhere AppCompatlibrary only (it already includes this annotations lib). Then delete all android-support-annotations.jarto avoid merging multiple versions of this library.

如果您AppCompat作为库项目导入并且android-support-annotations.jar在其他地方也有库,请确保AppCompat仅导入所有库(它已经包含此注释库)。然后全部删除android-support-annotations.jar以避免合并此库的多个版本。

回答by user2955733

Build->clean Project ,and it worked

Build->clean Project ,它起作用了

回答by Greg Alexander

Updating Android SDK Tools fixed it for me, now it just sees the copy in android-support-v4.jar.

更新 Android SDK 工具为我修复了它,现在它只看到android-support-v4.jar.

I had the same problem when using ant, and the annotations library was being included automatically by an outdated sdk.dir/tools/ant/build.xml.

我在使用 ant 时遇到了同样的问题,并且注释库被一个过时的sdk.dir/tools/ant/build.xml.

回答by Neamar

Clean project works as a temporary fix, but the issue will reappear on next compilation error.

Clean 项目可作为临时修复,但该问题将在下一次编译错误时再次出现。

To fix more reliably, I had to update the dependency to android support-v4to com.android.support:support-v4:22.2.0.

为了更可靠地修复,我不得不将 android 的依赖更新support-v4com.android.support:support-v4:22.2.0.

回答by Oliver

In my case I had a file called cache.xmlunder /build/intermediates/dex-cache/cache.xmlin the root project folder. I deleted this file, rebuild the project and it worked for me.

就我而言,我在根项目文件夹中有一个名为cache.xmlunder/build/intermediates/dex-cache/cache.xml的文件。我删除了这个文件,重建了项目,它对我有用。

回答by Cristian Traìna

As other users said, the first elements to troubleshoot are dependencies. Although, sometimes you can struggle for hours and you don't find any problem so you can focus on the build processinstead.

正如其他用户所说,首先要排除故障的是依赖项。虽然,有时您可能会挣扎几个小时,但没有发现任何问题,因此您可以专注于构建过程

Changing the way in which the .dexfiles are producedsometimes solves the problem. You can go through these steps:

更改生成文件的方式.dex有时可以解决问题。您可以完成以下步骤:

  • Open your Build.gradle (app)file
  • Search for the task dexOptions
  • Change it to:

    dexOptions {
      incremental false 
    }
    
  • 打开你的Build.gradle (app)文件
  • 搜索任务dexOptions
  • 将其更改为:

    dexOptions {
      incremental false 
    }
    

If you don't find the task in your file then you can add it.

如果您在文件中找不到该任务,则可以添加它。

回答by Dave MacDonald

Solved this exact issue in a Cordova project that used the facebook plugin. I was able to successfully build by commenting out this line from platforms\android\project.properties, as shown:

在使用 facebook 插件的 Cordova 项目中解决了这个确切的问题。通过从 注释掉这一行platforms\android\project.properties,我能够成功构建,如图所示:

# cordova.system.library.1=com.android.support:support-v4:+

And by commenting out this line from platforms\android\build.gradle, as shown:

并通过从 注释掉这一行platforms\android\build.gradle,如图所示:

// compile "com.android.support:support-v4:+"

Then doing the build. The problem started when I installed (katzer/cordova-plugin-local-notifications) which added these lines, but it created a conflict since the library it was adding to the build was already part of the facebook plugin build.

然后进行构建。当我安装添加这些行的 (katzer/cordova-plugin-local-notifications) 时,问题就开始了,但它造成了冲突,因为它添加到构建中的库已经是 facebook 插件构建的一部分。