Android的工作室:在APK复制重复文件META-INF /依赖性当编译 [英] Android Studio: Duplicate files copied in APK META-INF/DEPENDENCIES when compile

查看:347
本文介绍了Android的工作室:在APK复制重复文件META-INF /依赖性当编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我出口从Eclipse的我的项目,并使用在这个环节中的说明导入到Android工作室: http://developer.android.com/sdk/installing/migrate.html

I exported my project from Eclipse and imported to Android Studio using the instructions in this link: http://developer.android.com/sdk/installing/migrate.html

当我建,我有一个错误:

When I build, I have an error:

Duplicate files copied in APK META-INF/DEPENDENCIES

搜索后,我找到了解决方法:添加

After searching, I found a solution: add

packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
}

的build.gradle 。和它的作品!

但我不明白为什么我有这个错误,为什么我不得不应用该修补程序。有人能解释一下吗?

But I don't understand why I had this error and why I've had to apply that fix. Can anybody explain?

推荐答案

在Android的摇篮版本,你不允许包含具有相同路径比输出一次相同的文件。在你的构建,有两个 META-INF /相关内容来自不同地方来的文件。既然你不需要这个文件,同时在应用程序中,做最简单的事情就是告诉构建系统完全忽略它,这是这个排除指令做

In Android Gradle builds, you're not permitted to include the same file with the same path more than once in the output. In your build, there were two META-INF/DEPENDENCIES files coming from different places. Since you don't need this file at all in your application, the simplest thing to do is to tell the build system to ignore it altogether, which is what this exclude directive does.

还有一个 PICKFIRST 指令告诉构建系统保持的有一个的副本的;在<一个有细节的少量上href=\"http://stackoverflow.com/questions/20673625/android-gradle-plugin-0-7-0-duplicate-files-during-packaging-of-apk\">Android摇篮插件0.7.0:&QUOT; APK&QUOT的包装过程中重复的文件;

There's also a pickFirst directive to tell the build system to keep one of the copies; there's a tiny amount of detail on that in Android Gradle plugin 0.7.0: "duplicate files during packaging of APK".

Android的建立在摇篮是相当严格的关于重复文件,它可以使生活困难。如果包括同一个Java类不止一次有过类似的问题,你在哪里得到多DEX文件定义的错误(见<一href=\"http://stackoverflow.com/questions/20989317/multiple-dex-files-define-landroid-support-v4-accessibilityservice-accessibility\">Multiple DEX文件定义Landroid /支持/ V4 / accessibilityservice / AccessibilityServiceInfoCompat )为一个典型的例子)。

Android builds in Gradle are rather strict about duplicate files, which can make life difficult. There's a similar problem if you include the same Java class more than once, where you get the "Multiple dex files define" error (see Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat) for a typical example).

其他构建系统更加宽松。这是典型的在Java中,如果您在同一个班超过在类路径一次,例如,它看到的第一个副本是一个最使用;之后重复被忽略。这是在大多数情况下,更容易处理,但它有一对夫妇的问题。最大的一个是可以有细微的错误,如果多个不同版本的文件蠕变到构建没有你知道的 - 它可以是很难弄清楚发生了什么事情。当你看着办吧,你通常可以通过杂耍其中包含的东西,以确保你想要的,使得它最终的输出顺序解决它,但在非常复杂的构建,这是很难实现的,它可能发生,这样做看似不相关的事情一样,包括在你的项目新库可以打乱顺序,并导致大量的悲哀。

Other build systems are more lenient. It's typical in Java that if you include the same class more than once in a classpath, for example, the first copy it sees is the one that's used; duplicates after that are ignored. This is in most cases easier to deal with, but it has a couple problems. The biggest one is that there can be subtle errors if multiple different versions of a file creep into the build without you knowing -- it can be difficult to figure out what's going on. When you do figure it out, you can usually solve it by juggling the order in which things are included to make sure the one you want makes it to the final output, but in very complex builds, this can be difficult to achieve, and it can happen that doing seemingly unrelated things like including new libraries in your project can upset the ordering and lead to a lot of woe.

由于这个原因,摇篮还没有依靠的东西排序,以确定在解决重复的游戏赢家的经营理念,这迫使开发商做出的所有明确依赖。 Android的实现在摇篮之上的构建系统遵循这一理念。

For that reason, Gradle has the philosophy of not relying on ordering of things to determine "winners" in the game of resolving duplicates, and it forces the developer to make all dependencies explicit. Android's implementation of its build system on top of Gradle follows that philosophy.

这篇关于Android的工作室:在APK复制重复文件META-INF /依赖性当编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆