Sâm Nguyễn Văn
Sâm Nguyễn Văn

Reputation: 161

Error : duplicate files during packaging of APK

I try to run an android eclipse on Android Studio.

I try many solutions on the internet.

But something wrong still happens

Error:duplicate files during packaging of APK /home/sam/pst-adnew/panstage/build/outputs/apk/panstage-debug-unaligned.apk
	Path in archive: lib/armeabi-v7a/libmp3lame.so
	Origin 1: /home/sam/pst-adnew/panstage/build/intermediates/exploded-aar/pst-adnew/panstage_local_library/unspecified/jni/armeabi-v7a/libmp3lame.so
	Origin 2: /home/sam/pst-adnew/panstage/build/intermediates/ndk/debug/lib/armeabi-v7a/libmp3lame.so
You can ignore those files in your build.gradle:
	android {
	  packagingOptions {
	    exclude 'lib/armeabi-v7a/libmp3lame.so'
	  }
	}
Error:Execution failed for task ':panstage:packageDebug'.
> Duplicate files copied in APK lib/armeabi-v7a/libmp3lame.so
  	File 1: /home/sam/pst-adnew/panstage/build/intermediates/exploded-aar/pst-adnew/panstage_local_library/unspecified/jni/armeabi-v7a/libmp3lame.so
  	File 2: /home/sam/pst-adnew/panstage/build/intermediates/exploded-aar/pst-adnew/panstage_local_library/unspecified/jni/armeabi-v7a/libmp3lame.so

I am working with NDK android studio..

Please help me.

I also tried the solution

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }

But it does not work anymore. Please help me :(

Upvotes: 4

Views: 3190

Answers (3)

zeeshan
zeeshan

Reputation: 5053

I had a similar issue and the reason was that a module was included twice in the long gradle file and hard to notice.

.
.
.
compile project(path: ':common', configuration: 'debug')
.
.
.
compile project(path: ':common')
.
.
.

So once it was adding the files in the debug folder and second time in the release folder.

Once caught, I removed the second line, since we needed everything in the debug version. Error went away.

Upvotes: 0

Chandra Lakkimsetty
Chandra Lakkimsetty

Reputation: 322

In case of duplicate libraries (*.so) files, exclude option will not help as we cannot completely exclude the native binaries. There is one more option in packagingOptions. It is 'pickFirst'. We can avoid duplicate files error and include the first one the compiler encounters.

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        pickFirst 'lib/armeabi-v7a/libmp3lame.so'

    }

Upvotes: 12

Mohammad Arman
Mohammad Arman

Reputation: 7065

Include exclude 'lib/armeabi-v7a/libmp3lame.so' as well in the PackagingOption section.

packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
        exclude 'lib/armeabi-v7a/libmp3lame.so'

    }

Upvotes: 0

Related Questions