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

查看:58
本文介绍了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

当我构建时,我有一个错误:

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 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天全站免登陆