Android Studio:编译时在 APK META-INF/DEPENDENCIES 中复制的重复文件 [英] Android Studio: Duplicate files copied in APK META-INF/DEPENDENCIES when compile

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

问题描述

我使用以下链接中的说明从 Eclipse 导出我的项目并导入到 Android Studio: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

构建时出现错误:

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 Gradle 构建中,不允许在输出中多次包含具有相同路径的相同文件.在您的构建中,有两个 META-INF/DEPENDENCIES 文件来自不同的地方.由于您的应用程序中根本不需要这个文件,最简单的做法是告诉构建系统完全忽略它,这就是 exclude 指令的作用.

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 指令告诉构建系统保留 一个 个副本;Android Gradle 插件 0.7.0:打包 APK 期间重复文件".

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".

Gradle 中的 Android 构建对重复文件非常严格,这会让生活变得困难.如果您多次包含同一个 Java 类,则会出现类似的问题,您会收到多个 dex 文件定义"错误(请参阅 多个dex文件定义Landroid/support/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.

出于这个原因,Gradle 的理念是在解决重复问题的游戏中不依赖事物的排序来确定赢家",它迫使开发人员明确所有依赖关系.Android 在 Gradle 之上的构建系统的实现遵循了这一理念.

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 Studio:编译时在 APK META-INF/DEPENDENCIES 中复制的重复文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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