Android Studio external jar Error

11,853

Solution 1

I faced the same problem and I adopted the above mentioned logic ie. adding

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

in build.gradle ... But it didn't work for me and I added the following code that eventually worked... Adding the following code in build.gradle

       android {
       packagingOptions {
       exclude 'META-INF/DEPENDENCIES.txt'
       exclude 'META-INF/LICENSE.txt'
       exclude 'META-INF/NOTICE.txt'
       exclude 'META-INF/NOTICE'
       exclude 'META-INF/LICENSE'
       exclude 'META-INF/DEPENDENCIES'
       exclude 'META-INF/notice.txt'
       exclude 'META-INF/license.txt'
       exclude 'META-INF/dependencies.txt'
       exclude 'META-INF/LGPL2.1'
       }

Solution 2

This question is duplicate. For resolve it you must add

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

in build.gradle

Solution 3

I also faced this same problem. Some files have the ".txt" and some do not. If you keep adding one exclude at a time and run your app, you will see in the "Messages Gradle Build" window all the files needed to exclude in your project. All I needed was this code and it solved my problem.

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

Solution 4

I faced the same issue. I added this code:

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

inside my build.gradle Module:app into the section android{}

At the end, my adroid section on build.gradle. Module app is:

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "com.example.myapp"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"

        // Enabling multidex support.
        multiDexEnabled true
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
        packagingOptions {
            exclude 'META-INF/LICENSE.txt'
            exclude 'META-INF/LICENSE'
            exclude 'META-INF/LICENSE-FIREBASE.txt'
            exclude 'META-INF/NOTICE'
        }

}
Share:
11,853
Jossy Joy
Author by

Jossy Joy

Updated on June 04, 2022

Comments

  • Jossy Joy
    Jossy Joy almost 2 years
    Information:Gradle tasks [:app:assembleDebug]
    :app:preBuild UP-TO-DATE
    :app:preDebugBuild UP-TO-DATE
    :app:checkDebugManifest
    :app:preReleaseBuild UP-TO-DATE
    :app:prepareComAndroidSupportAppcompatV72311Library UP-TO-DATE
    :app:prepareComAndroidSupportDesign2311Library UP-TO-DATE
    :app:preDebugAndroidTestBuild UP-TO-DATE
    :app:prepareComAndroidSupportMultidex101Library UP-TO-DATE
    :app:prepareComAndroidSupportRecyclerviewV72311Library UP-TO-DATE
    :app:prepareComAndroidSupportSupportV42311Library UP-TO-DATE
    :app:prepareDebugDependencies
    :app:compileDebugAidl UP-TO-DATE
    :app:compileDebugRenderscript UP-TO-DATE
    :app:generateDebugBuildConfig UP-TO-DATE
    :app:generateDebugAssets UP-TO-DATE
    :app:mergeDebugAssets UP-TO-DATE
    :app:generateDebugResValues UP-TO-DATE
    :app:generateDebugResources UP-TO-DATE
    :app:mergeDebugResources UP-TO-DATE
    :app:processDebugManifest UP-TO-DATE
    :app:processDebugResources UP-TO-DATE
    :app:generateDebugSources UP-TO-DATE
    :app:compileDebugJavaWithJavac UP-TO-DATE
    :app:compileDebugNdk UP-TO-DATE
    :app:compileDebugSources UP-TO-DATE
    :app:transformClassesWithJarMergingForDebug UP-TO-DATE
    :app:collectDebugMultiDexComponents UP-TO-DATE
    :app:transformClassesWithMultidexlistForDebug UP-TO-DATE
    :app:transformClassesWithDexForDebug UP-TO-DATE
    :app:mergeDebugJniLibFolders UP-TO-DATE
    :app:transformNative_libsWithMergeJniLibsForDebug UP-TO-DATE
    :app:processDebugJavaRes UP-TO-DATE
    :app:transformResourcesWithMergeJavaResForDebug FAILED
    
    
    Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebug'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/license.txt   File1: C:\Users\system2\AndroidStudioProjects\PorjectName\app\libs\spring-android-rest-template-2.0.0.M1.jar    File2: C:\Users\system2\AndroidStudioProjects\ProjectName\app\libs\spring-android-core-2.0.0.M1.jar