DuplicateFileException error while building Android APK

前端 未结 3 904
自闭症患者
自闭症患者 2020-12-10 15:41

I am using Android Studio 2.0 on Windows 7. When building my Android project, I get the following error:

:app:transformResourcesWithMergeJavaResForDebug FAIL         


        
相关标签:
3条回答
  • 2020-12-10 16:11

    To complete @dsh's answer:

    In your dependency tree there are 2 jar files containing the same file named sep_approx_spanish.txt , this is not allowed.

    To resolve your problem you have to track down which of your gradle dependencies has the two jars named appengine-api-1.0-sdk-1.9.28.jar and appengine-endpoints-1.9.28.jar; to do this you can open android studio's terminal console and type in:

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

    You will see gradle doing a lot of things, but at a certain point it will print the entire dependency tree. Once you find which are the 2 dependencies are causing the problem, add this piece of code at the end of one of the dependency declarations

    {
        exclude "sep_approx_spanish.txt"
    }
    

    So for example if the two dependencies are these

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

    if must become

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

    or

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

    in this way you tell to gradle to not take into consideration that file for one of the two libraries, avoiding the file's duplication inside the apk.

    0 讨论(0)
  • 2020-12-10 16:23

    Completing @Apperside answer.

    I fixed the error by adding the following lines to my build.gradle file of my app module:

    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/*'
            }
    
        (...)  
    }
    
    0 讨论(0)
  • 2020-12-10 16:30

    The error tells you that building your APK would result in two files named com/google/appengine/repackaged/org/apache/commons/codec/language/bm/sep_approx_spanish.txt. This is a failure because the APK can only contain one file at any given path. This is probably caused by two different jar files in your classpath that contain the file. In my project, this only occurred with files that were not actually used at runtime so I excluded them from the APK entirely.

    0 讨论(0)
提交回复
热议问题