构建Android APK时出现DuplicateFileException错误



我使用的是Windows 7上的Android Studio 2.0。在构建我的Android项目时,我得到以下错误:

:app:transformResourcesWithMergeJavaResForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt
File1: C:UsersUSER.gradlecachesmodules-2files-2.1com.google.appengineappengine-api-1.0-sdk1.9.28e92c18272b555027d9ec666e7a89162f10638314appengine-api-1.0-sdk-1.9.28.jar
File2: C:UsersUSER.gradlecachesmodules-2files-2.1com.google.appengineappengine-endpoints1.9.28bf2e8a74bd28e388b3487fc78a0c7adfa592fd5dappengine-endpoints-1.9.28.jar`

我已经挖了好几个小时了,没有发现任何原因。我已经删除了主目录中的.gradle,但它只是重新构建它。有人知道是什么原因造成的吗?

全等级输出:

Executing tasks: [:app:clean, :app:generateDebugSources, :app:mockableAndroidJar, :app:prepareDebugUnitTestDependencies, :app:generateDebugAndroidTestSources, :app:assembleDebug]
Configuration on demand is an incubating feature.
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for debug as it may be conflicting with the internal version provided by Android.
     In case of problem, please repackage it with jarjar to change the class packages
WARNING: Dependency org.apache.httpcomponents:httpclient:4.0.1 is ignored for release as it may be conflicting with the internal version provided by Android.
     In case of problem, please repackage it with jarjar to change the class packages
Incremental java compilation is an incubating feature.
:app:clean
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:backend:appengineDownloadSdk
:backend:compileJava
:backend:processResources UP-TO-DATE
:backend:classes
:backend:appengineEndpointsGetClientLibs UP-TO-DATE
:backend:appengineEndpointsExpandClientLibs UP-TO-DATE
:backend:compileEndpointsSrcJava
:backend:processEndpointsSrcResources UP-TO-DATE
:backend:endpointsSrcClasses
:backend:_appengineEndpointsAndroidArtifact UP-TO-DATE
:backend:jar UP-TO-DATE
:app:prepareComAndroidSupportAnimatedVectorDrawable2330Library
:app:prepareComAndroidSupportAppcompatV72330Library
:app:prepareComAndroidSupportSupportV42330Library
:app:prepareComAndroidSupportSupportVectorDrawable2330Library
:app:prepareComGoogleAndroidGmsPlayServicesAuth840Library
:app:prepareComGoogleAndroidGmsPlayServicesBase840Library
:app:prepareComGoogleAndroidGmsPlayServicesBasement840Library
:app:prepareComGoogleAndroidGmsPlayServicesMeasurement840Library
:app:prepareDebugDependencies
:app:compileDebugAidl
:app:compileDebugRenderscript
:app:generateDebugBuildConfig
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets
:app:generateDebugResValues UP-TO-DATE
:app:processDebugGoogleServices
:app:generateDebugResources
:app:mergeDebugResources
:app:processDebugManifest
:app:processDebugResources
:app:generateDebugSources
:app:mockableAndroidJar UP-TO-DATE
:app:preDebugUnitTestBuild UP-TO-DATE
:app:prepareDebugUnitTestDependencies
:app:preDebugAndroidTestBuild UP-TO-DATE
:app:prepareDebugAndroidTestDependencies
:app:compileDebugAndroidTestAidl
:app:processDebugAndroidTestManifest
:app:compileDebugAndroidTestRenderscript
:app:generateDebugAndroidTestBuildConfig
:app:generateDebugAndroidTestAssets UP-TO-DATE
:app:mergeDebugAndroidTestAssets
:app:generateDebugAndroidTestResValues UP-TO-DATE
:app:generateDebugAndroidTestResources
:app:mergeDebugAndroidTestResources
:app:processDebugAndroidTestResources
:app:generateDebugAndroidTestSources
:app:compileDebugJavaWithJavac
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
:app:compileDebugNdk UP-TO-DATE
:app:compileDebugSources
:app:buildInfoDebugLoader
:app:transformClassesWithExtractJarsForDebug
:app:transformClassesWithInstantRunVerifierForDebug
:app:transformClassesWithJavaResourcesVerifierForDebug UP-TO-DATE
:app:mergeDebugJniLibFolders
:app:transformNative_libsWithMergeJniLibsForDebug
:app:processDebugJavaRes UP-TO-DATE
:app:transformResourcesWithMergeJavaResForDebug FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'.
> com.android.build.api.transform.TransformException:     com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt
File1: C:UsersUSER.gradlecachesmodules-2files-2.1com.google.appengineappengine-api-1.0-sdk1.9.28e92c18272b555027d9ec666e7a89162f10638314appengine-api-1.0-sdk-1.9.28.jar
File2: C:UsersUSER.gradlecachesmodules-2files-2.1com.google.appengineappengine-endpoints1.9.28bf2e8a74bd28e388b3487fc78a0c7adfa592fd5dappengine-endpoints-1.9.28.jar

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 15.364 secs

据我所知,这是两个依赖项之间的冲突:

dependencies {
  appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.28'
  compile 'com.google.appengine:appengine-endpoints:1.9.28'
  compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'
  compile 'javax.servlet:servlet-api:2.5'
  compile 'com.google.http-client:google-http-client-jackson2:1.20.0'
  compile 'com.google.http-client:google-http-client-gson:1.19.0'
}

我认为是这两个依赖:

appengineSdk 'com.google.appengine:appengine-java-sdk:1.9.28'
compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'

我无法删除其中任何一个,因为它会导致后端模块上的编译错误。然而,看起来这两个依赖关系几乎完全相同。他们应该都在里面吗?欢迎提出任何建议!

要完成@dsh的回答:

在依赖关系树中,有两个jar文件包含同一个名为sep_approx_spanish.txt的文件,这是不允许的。

为了解决您的问题,您必须追踪哪个gradle依赖项具有两个名为appengine-api-1.0-sdk-1.9.28.jarappengine-endpoints-1.9.28.jar的jar;要做到这一点,你可以打开android工作室的终端控制台并键入:

//if ou are on windows
gradlew dependencies
//if you are on unix based os
./gradlew dependencies

你会看到gradle做了很多事情,但在某个时刻,它会打印整个依赖树。一旦您发现是哪两个依赖项导致了问题,请在其中一个依赖项声明的末尾添加这段代码

{
    exclude "sep_approx_spanish.txt"
}

例如,如果这两个依赖项是

compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28

如果必须成为

compile 'com.google.appengine:appengine-endpoints:1.9.28'{
        exclude "sep_approx_spanish.txt"
    }
 compile 'com.google.appengine:appengine-endpoints-deps:1.9.28

compile 'com.google.appengine:appengine-endpoints:1.9.28'
compile 'com.google.appengine:appengine-endpoints-deps:1.9.28'{
        exclude "sep_approx_spanish.txt"
    }

通过这种方式,您可以告诉gradle不要为两个库中的一个库考虑该文件,从而避免文件在apk中的重复。

错误告诉您构建APK将导致两个名为com/google/appengine/repackaged.org/apache/commons/cocodec/language/bm/sep_approx_spanish.txt的文件。这是一个失败,因为APK在任何给定的路径上只能包含一个文件。这可能是由类路径中包含该文件的两个不同的jar文件引起的。在我的项目中,这种情况只发生在运行时没有实际使用的文件中,所以我将它们完全排除在APK之外。

完成@Apperside答案。

我通过在应用程序模块的build.gradle文件中添加以下行来修复错误:

android{
    packagingOptions {
            exclude 'com/google/appengine/repackaged/org/apache/commons/codec/language/bm/*'
            exclude 'com/google/appengine/repackaged/org/codehaus/jackson/impl/VERSION.txt'
            exclude 'com/google/appengine/repackaged/org/apache/commons/codec/language/*'
        }
    (...)  
}

相关内容

  • 没有找到相关文章

最新更新