John Smith
John Smith

Reputation: 3615

Can't get rid of error "Duplicate files copied in APK META-INF/beans.xml" in Android Studio 2.2

I get the following error:

Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForRelease'. > com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK META-INF/beans.xml File1: /Users/david/AndroidStudioProjects/AndroidDLNA/app/libs/cling-support-2.1.1.jar File2: /Users/david/AndroidStudioProjects/AndroidDLNA/app/libs/cling-core-2.1.1.jar

What happened was I was having problems getting

compile fileTree(dir: 'app/libs', include: ['*.jar'])

to work and added "include ':library' to gradle.settings and it appeared to work to detect libraries but then I got the above error creating apk. I removed the line from gradle.settings and got a prompt about removing something else which I said yes but the above error remains. I've tried creating a project from scratch and only moving in Java and Res but still the same error. I've tried clearing out .m2 where I found the libraries but still same error. I've scoured the drive and no bean.xml exists.

UPDATE: The packageOptions directive made no difference. build.gradle

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.2"
    defaultConfig {
      ...
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/NOTICE.txt'
    }
}

Upvotes: 0

Views: 304

Answers (2)

John Smith
John Smith

Reputation: 3615

Ok. For those who haven't a clue what the error is (like me) it is saying that the file META-INF/beans.xml was in MULTIPLE JAR FILES IN THE LIBS DIR. Here is the correct syntax for ignoring the file.

android {
...
    packagingOptions {
        exclude 'META-INF/beans.xml'
    }
}

Upvotes: 2

pRaNaY
pRaNaY

Reputation: 25312

You just need to add packagingOptions in your build.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'
  }
}

Upvotes: 0

Related Questions