在APK META-INF / services /中复制的Android重复文件

时间:2016-08-09 02:15:33

标签: android android-studio

我正在尝试在Android上创建自己的应用程序但是当我尝试运行应用程序时出现以下错误

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/services/com.fasterxml.jackson.databind.Module
    File1: /home/eric/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jsr310/2.7.3/e41a3c103f5017794bd866528ec359ae70f5f875/jackson-datatype-jsr310-2.7.3.jar
    File2: /home/eric/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-jdk8/2.7.3/2390f30d097229e043a0bde30fa1ba8f9b0d951b/jackson-datatype-jdk8-2.7.3.jar
    File3: /home/eric/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.datatype/jackson-datatype-guava/2.7.3/7fa709967be660a704d8b42e43d6811bf52a83fc/jackson-datatype-guava-2.7.3.jar
    File4: /home/eric/.gradle/caches/modules-2/files-2.1/com.fasterxml.jackson.module/jackson-module-afterburner/2.7.3/27b8222af569ecd9e718fa7e697fbb22045a98c4/jackson-module-afterburner-2.7.3.jar

这个错误让我发疯,我做了很多搜索,但没有任何对我有用,大多数情况下这些家伙建议使用packagingOptions并排除META-INF我试过这个例如:

 packagingOptions {
        exclude 'META-INF/services'
    }
你能帮助我吗?

更新

我添加了TML建议,现在我收到以下错误

Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.dom.DOMNodeHelper$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.io.DocumentInputSource$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.rule.RuleManager$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.swing.LeafTreeNode$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.swing.BranchTreeNode$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:warning: Ignoring InnerClasses attribute for an anonymous inner class
Error:(org.dom4j.xpath.DefaultXPath$1) that doesn't come with an
Error:associated EnclosingMethod attribute. This class was probably produced by a
Error:compiler that did not target the modern .class file format. The recommended
Error:solution is to recompile the class from source, using an up-to-date compiler
Error:and without specifying any "-target" type options. The consequence of ignoring
Error:this warning is that reflective operations on this class will incorrectly
Error:indicate that it is *not* an inner class.
Error:trouble processing "javax/xml/parsers/DocumentBuilder.class":
Error:Ill-advised or mistaken usage of a core class (java.* or javax.*)
Error:when not building a core library.
Error:This is often due to inadvertently including a core library file
Error:in your application's project, when using an IDE (such as
Error:Eclipse). If you are sure you're not intentionally defining a
Error:core class, then this is the most likely explanation of what's
Error:going on.
Error:However, you might actually be trying to define a class in a core
Error:namespace, the source of which you may have taken, for example,
Error:from a non-Android virtual machine project. This will most
Error:assuredly not work. At a minimum, it jeopardizes the
Error:compatibility of your app with future versions of the platform.
Error:It is also often of questionable legality.
Error:If you really intend to build a core library -- which is only
Error:appropriate as part of creating a full virtual machine
Error:distribution, as opposed to compiling an application -- then use
Error:the "--core-library" option to suppress this error message.
Error:If you go ahead and use "--core-library" but are in fact
Error:building an application, then be forewarned that your application
Error:will still fail to build or run, at some point. Please be
Error:prepared for angry customers who find, for example, that your
Error:application ceases to function once they upgrade their operating
Error:system. You will be to blame for this problem.
Error:If you are legitimately using some code that happens to be in a
Error:core package, then the easiest safe alternative you have is to
Error:repackage that code. That is, move the classes in question into
Error:your own package namespace. This means that they will never be in
Error:conflict with core system classes. JarJar is a tool that may help
Error:you in this endeavor. If you find that you cannot do this, then
Error:that is an indication that the path you are on will ultimately
Error:lead to pain, suffering, grief, and lamentation.
Error:1 error; aborting
Error:Execution failed for task ':app:transformClassesWithDexForDebug'.
> com.android.build.api.transform.TransformException: java.lang.RuntimeException: com.android.ide.common.process.ProcessException: java.util.concurrent.ExecutionException: com.android.ide.common.process.ProcessException: Return code 1 for dex process
Information:BUILD FAILED
Information:Total time: 19.099 secs
Error:Error converting bytecode to dex:
Cause: Dex cannot parse version 52 byte code.
This is caused by library dependencies that have been compiled using Java 8 or above.
If you are using the 'java' gradle plugin in a library submodule add 
targetCompatibility = '1.7'
sourceCompatibility = '1.7'
to that submodule's build.gradle file.
Error:1 error; aborting

3 个答案:

答案 0 :(得分:2)

我刚刚遇到了几乎完全相同的问题。

添加此代码,就像TML说的那样,为我解决了这个问题:

android {

    packagingOptions {
        exclude 'META-INF/services/com.fasterxml.jackson.databind.Module'
    }

}

答案 1 :(得分:1)

我刚刚帮助过有类似问题的人:Android Gradle Duplicate files copied in APK META-INF

每当看到Exception: Duplicate files copied in APK BLAH/blaha.blahb.blahc

将另一个exclude 'BLAH/blaha.blahb.blahc'添加到您的packagingOptions

所以在你的情况下:exclude 'META-INF/services/com.fasterxml.jackson.databind.Module'

这种异常可能会多次发生,直到你全部抓住它们为止!

答案 2 :(得分:0)

在buildTypes:

下面的build.gradle文件中使用以下行
packagingOptions {
    exclude 'META-INF/NOTICE.txt' // will not include NOTICE file
    exclude 'META-INF/LICENSE.txt' // will not include LICENSE file
}

并在同一文件中添加defaultConfig

multiDexEnabled true