Duplicate files during packaging of APK app-debug-unaligned.apk
Solution 1
You can replace compile files('libs/httpmime-4.3.5.jar')
with this compile 'org.apache.httpcomponents:httpmime:4.3.5'
.
Also you are duplicating the dependencies compile fileTree(include: ['*.jar'], dir: 'libs')
already includes compile files('libs/httpmime-4.3.5.jar')
Solution 2
update your build.gradle and add the following lines
android{
.
.
.
packagingOptions {
exclude 'META-INF/license.txt'
exclude 'META-INF/LICENSE'
exclude 'META-INF/notice.txt'
exclude 'META-INF/NOTICE'
}
}
this will fix this error. I got the same error, doing this fixed it.
Huy Tower
Huy Tower --- Flutter Developer | Senior Android Developer --- Skype: huytower Location : Ho Chi Minh, Viet Nam
Updated on July 09, 2022Comments
-
Huy Tower almost 2 years
I got this error
Duplicate files during packaging of APK app-debug-unaligned.apk
when put 2 jar files :httpclient-4.3.5.jar
httpmime-4.3.5.jar
into the
libs
folder afterSync with Gradle
andRun
.
If user 1 jar file -
httpmime-4.3.5.jar
, I will not get this error.Please help me how to avoid this error & still can use 2 jar files in above also,
Thanks,
p/s : I use Android Studio version 0.8.6.
Error Detail
Error:duplicate files during packaging of APK ...\app\build\outputs\apk\app-debug-unaligned.apk Path in archive: META-INF/DEPENDENCIES Origin 1: ...\app\libs\httpclient-4.3.5.jar Origin 2: ...\app\libs\httpmime-4.3.5.jar
build.gradle
android { compileSdkVersion 20 buildToolsVersion '20.0.0' defaultConfig { applicationId 'com.app' minSdkVersion 9 targetSdkVersion 20 versionCode 1 versionName '1.0' } buildTypes { release { runProguard false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } productFlavors { } packagingOptions { exclude 'META-INF/LICENSE.txt' } dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') compile 'com.android.support:support-v4:20.0.0' compile 'com.android.support:appcompat-v7:20.0.0' compile 'com.google.android.gms:play-services:5.2.08' compile 'com.viewpagerindicator:library:2.4.1@aar' compile 'de.hdodenhof:circleimageview:1.2.0' compile files('libs/httpmime-4.3.5.jar') }
UPDATE
I changed fromcompile files('libs/httpmime-4.3.5.jar')
to use Maven Link. I got same error again after put 2 maven link together:compile 'org.apache.httpcomponents:httpmime:4.4-alpha1' compile 'org.apache.httpcomponents:httpcore:4.4-alpha1'
This is the warning
Warning:Dependency org.apache.httpcomponents:httpclient:4.4-alpha1 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.4-alpha1 is ignored for release as it may be conflicting with the internal version provided by Android. In case of problem, please repackage it with jar to change the class packages
Please help me fix.
SOULITION I know good answer now by addding these lines will fix
Duplicate files
error :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' }
-
Huy Tower over 9 yearsI get same error again after put 2 maven link, pls help me how to fix this error. If put 1 maven link, it is okay. I will unaccept your question since I want many people tell me how to fix. Thank you.
-
hoomi over 9 yearsWhat are the two maven links that you put?
-
hoomi over 9 yearsThe problem is that Android is already using apache httpclient. Is there a reason that u want to reimport it?
-
Huy Tower over 9 yearsI already update my solution in my question. I don't know why. You know?
-
hoomi over 9 yearsjust remove the httpclient maven line and also remove the jar file. Unless you need a new function which is not available in the older versions you do need to reimport it
-
Huy Tower over 9 yearsNo, I should use http-client, http-core ... and so the other *.jar files.
-
hoomi over 9 yearsHave a look at this developer.android.com/reference/org/apache/http/…. If you have all the classes that you need then you can stop importing them
-
Huy Tower over 9 yearsAh, u see. I need use the other class had not had in Android SDK. ex. HTTPMuptile class ... u see, I want to upload multiple files ...
-
hoomi over 9 yearsI am not sure if you can override android libraries. Maybe you could find the source to the classes that you need and then import them directly
-
IgorGanapolsky about 9 years~"remove all the dependancy file from the system". How is that applicable to gradle builds?
-
Nirmal Dhara about 9 yearsno not using the gradle build. gradle download the duplicated jars in your system. we need to physically remove the folder of the jar file from your system, before you build the project again.
-
user1767754 almost 9 yearsYou should clarify your answer again, its not easy to follow... thats why there are so many commant though
-
Chris Ho over 8 yearssometime you need add exclude 'META-INF/DEPENDENCIES'
-
Sadeq Shajary about 8 yearsalso you should add 'exclude 'META-INF/LICENSE.txt'' ' exclude 'META-INF/NOTICE.txt''
-
Gaurav Sharma about 8 years@SadeqShajary you actually don't.... Only the above mentioned files are sufficient to resolve this error