web-dev-qa-db-ja.com

コピーされた重複ファイル(Android Studio 0.4.0)

私のプロジェクトでは、Apacheのhttpcoreおよびhttpmimeライブラリを使用しています。 Android St​​udioを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ライブラリのローカルコピーから問題が発生したファイルを削除することで、この問題を解決できました。

111
Slava

このバグのコメント14によると、 https://code.google.com/p/Android/issues/detail?id=61573#c14 これは、Android Gradleプラグイン。0.7.1で間もなく修正される予定です。

編集

0.7.1の追加に関するバグの注意事項を以下に示します。

0.7.1は、この修正とともにリリースされています。

ファイルを除外するDSLは次のとおりです。

Android {
    packagingOptions {
        exclude 'META-INF/LICENSE.txt'
    }
}

Excludeステートメントは必要な数だけ追加できます。値はアーカイブパスです。ワイルドカードやグロブはまだサポートされていません。

96
Scott Barta

ビルドの最後に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'
    }
    // ...
}
284
SK9