Dans mon projet, j'utilise les bibliothèques httpcore et httpmime d'Apache. Après la mise à jour Android Studio to 0.4.0), je suis confronté au problème suivant:
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
Voici la pile de compilation de 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
Le build.gradle ressemble à ceci:
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'
}
Edit 1: Gestion de ce problème en supprimant des fichiers de la copie locale de la bibliothèque httpmime dans le répertoire META-INF.
Selon le commentaire 14 de ce bogue: https://code.google.com/p/Android/issues/detail?id=61573#c14 il s’agit d’un bogue de la v0.7.0 du Android Gradle, et doit être corrigé prochainement dans la version 0.7.1.
MODIFIER
Voici les notes de ce bogue concernant l'ajout de la version 0.7.1:
0.7.1 est sorti avec le correctif pour cela.
Le DSL pour exclure des fichiers est:
Android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
}
Vous pouvez ajouter autant d'instructions d'exclusion que vous le souhaitez. La valeur est le chemin d'archive. Pas de support générique ou global pour le moment.
Suivez les conseils que Gradle vous donne à la fin de la construction. Dans mon cas, il m'a dit d'ajouter:
Android {
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/NOTICE'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}
// ...
}