复制的文件重复(Android Studio 0.4.0)[重复]

Posted

技术标签:

【中文标题】复制的文件重复(Android Studio 0.4.0)[重复]【英文标题】:Duplicate files copied (Android Studio 0.4.0) [duplicate] 【发布时间】:2014-01-07 13:27:17 【问题描述】:

在我的项目中,我使用来自 Apache 的 httpcore 和 httpmime 库。将 android Studio 更新到 0.4.0 后,我在构建项目时遇到了这个问题:

Duplicate files copied in APK META-INF/DEPENDENCIES
File 1: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar
File 2: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar

这是 Gradle 构建的堆栈跟踪:

org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':CMO:packageDebug'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.execute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExecuter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.execute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execute(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecuter.execute(SkipEmptySourceFilesTaskExecuter.java:42)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execute(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.api.internal.AbstractTask.executeWithoutThrowingTaskFailure(AbstractTask.java:286)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.executeTask(AbstractTaskPlanExecutor.java:79)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.processTask(AbstractTaskPlanExecutor.java:63)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorWorker.run(AbstractTaskPlanExecutor.java:51)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor$1.run(DefaultTaskPlanExecutor.java:33)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:198)
        at org.gradle.cache.internal.DefaultCacheAccess.longRunningOperation(DefaultCacheAccess.java:266)
        at org.gradle.cache.internal.DefaultPersistentDirectoryStore.longRunningOperation(DefaultPersistentDirectoryStore.java:135)
        at org.gradle.api.internal.changedetection.state.DefaultTaskArtifactStateCacheAccess.longRunningOperation(DefaultTaskArtifactStateCacheAccess.java:93)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(DefaultTaskPlanExecutor.java:31)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(DefaultTaskGraphExecuter.java:86)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTaskExecutionAction.java:29)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.access$200(DefaultBuildExecuter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$2.proceed(DefaultBuildExecuter.java:67)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildExecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:61)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecuter.java:54)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(DefaultGradleLauncher.java:166)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradleLauncher.java:113)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLauncher.java:81)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildController.run(InProcessBuildActionExecuter.java:64)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:33)
        at org.gradle.launcher.cli.ExecuteBuildAction.run(ExecuteBuildAction.java:24)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProcessBuildActionExecuter.java:26)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:50)
        at org.gradle.api.internal.Actions$RunnableActionAdapter.execute(Actions.java:171)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:201)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.execute(CommandLineActionFactory.java:174)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(CommandLineActionFactory.java:139)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionReportingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:46)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.Main.main(Main.java:37)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBootstrap.java:50)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.java:32)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
        at org.gradle.wrapper.BootstrapMainStarter.start(BootstrapMainStarter.java:30)
        at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:127)
        at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:58)
Caused by: org.gradle.tooling.BuildException: Duplicate files copied in APK META-INF/DEPENDENCIES
        File 1: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar
        File 2: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar

        at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(PackageApplication.groovy:93)
        at com.android.build.gradle.internal.tasks.IncrementalTask.taskAction(IncrementalTask.groovy:64)
        at org.gradle.internal.reflect.JavaMethod.invoke(JavaMethod.java:63)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.doExecute(AnnotationProcessingTaskFactory.java:236)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:212)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$IncrementalTaskAction.execute(AnnotationProcessingTaskFactory.java:223)
        at org.gradle.api.internal.project.taskfactory.AnnotationProcessingTaskFactory$StandardTaskAction.execute(AnnotationProcessingTaskFactory.java:201)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:530)
        at org.gradle.api.internal.AbstractTask$TaskActionWrapper.execute(AbstractTask.java:513)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.executeActions(ExecuteActionsTaskExecuter.java:61)
        ... 52 more
Caused by: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/DEPENDENCIES
        File 1: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar
        File 2: /home/slava/.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.1/f7899276dddd01d8a42ecfe27e7031fcf9824422/httpmime-4.3.1.jar

        at com.android.builder.internal.packaging.Packager$JavaAndNativeResourceFilter.checkEntry(Packager.java:129)
        at com.android.builder.signing.SignedJarBuilder.writeZip(SignedJarBuilder.java:258)
        at com.android.builder.internal.packaging.Packager.addResourcesFromJar(Packager.java:386)
        at com.android.builder.AndroidBuilder.packageApk(AndroidBuilder.java:1175)
        at com.android.builder.AndroidBuilder$packageApk.call(Unknown Source)
        at com.android.build.gradle.tasks.PackageApplication.doFullTaskAction(PackageApplication.groovy:86)
        ... 62 more

build.gradle 看起来像这样:

    buildscript 
    repositories 
        mavenCentral()
    
    dependencies 
        classpath 'com.android.tools.build:gradle:0.7.0'
    

apply plugin: 'android'

repositories 
    mavenCentral()


android 
    compileSdkVersion 19
    buildToolsVersion '19.0.0'

    defaultConfig 
        minSdkVersion 14
        targetSdkVersion 19
    

    compileOptions 
        sourceCompatibility JavaVersion.VERSION_1_7
        targetCompatibility JavaVersion.VERSION_1_7
    

    signingConfigs 
        debug 
            storeFile file('debug.keystore')
        
    


dependencies 
    compile project(':Inflector')
    compile 'com.android.support:support-v13:+'
    compile 'com.google.code.gson:gson:2.2.4'
    compile 'com.google.guava:guava:15.0'
    compile 'org.apache.httpcomponents:httpcore:4.3'
    compile 'org.apache.httpcomponents:httpmime:4.3.1'

编辑 1: 设法解决了这个问题,从 META-INF 目录中 httpmime 库的本地副本中删除了我遇到问题的文件

【问题讨论】:

这似乎是错误code.google.com/p/android/issues/detail?id=61573。我不知道为什么在这个版本中它才开始给你带来麻烦。 这是重复的,但只有 26 分钟。即使问题最终被关闭,我也希望 OP 能被原谅。 【参考方案1】:

遵循 Gradle 在构建结束时为您提供的建议。就我而言,它告诉我添加:

android 
    packagingOptions 
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    
    // ...

【讨论】:

它不符合关于 NOTICE 文件的 Apache 2.0 许可证,不是吗?还是应该提取所有 NOTICE 文件并加入它们? 我已经添加了所有这些。但我仍然有同样的问题。我还能改变什么? 我在添加 Azure 移动服务时遇到了这个问题。现在它得到解决。添加以下行解决了问题:packagingOptions exclude "META-INF/MSFTSIG.SF" exclude "META-INF/MSFTSIG.RSA" 【参考方案2】:

根据此错误中的评论 14:https://code.google.com/p/android/issues/detail?id=61573#c14 这是 Android Gradle 插件 v0.7.0 中的错误,将很快在 0.7.1 中修复。

编辑

以下是该错误中关于 0.7.1 添加的注释:

0.7.1 已经解决了这个问题。

排除文件的DSL是:

android 
    packagingOptions 
        exclude 'META-INF/LICENSE.txt'
    

您可以根据需要添加任意数量的排除语句。该值是存档路径。尚无通配符或 glob 支持。

【讨论】:

我还必须输入 'META_INF/NOTICE.txt' 以供 commons-lang3-3.1.jar 使用。 从 SK9 检查下面的答案,排除所有必要的文件。 @Scott Barta 不会导致开源违规吗?

以上是关于复制的文件重复(Android Studio 0.4.0)[重复]的主要内容,如果未能解决你的问题,请参考以下文章

Android Studio 不下载 SDK。详细重复的相同 zip 文件

如何在 Android Studio 3.4 中复制和重命名项目?

我如何将PDF复制到内部存储中? -Android studio

在 Android Studio 1.0 中添加 JAR [重复]

将 Android Studio 的 Gradle 插件升级到 3.0.1 和 Gradle 到 4.1 后无法复制配置依赖项

mac 电脑中 Android studio 复制文件或文件夹