Android 打包 APK app-debug-unaligned.apk 期间出现重复文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25483410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:29:06  来源:igfitidea点击:

Duplicate files during packaging of APK app-debug-unaligned.apk

androidhttpjarandroid-studioapache-commons-httpclient

提问by Huy Tower

I got this error Duplicate files during packaging of APK app-debug-unaligned.apkwhen put 2 jar files :

Duplicate files during packaging of APK app-debug-unaligned.apk放入 2 个 jar 文件时出现此错误:

  • httpclient-4.3.5.jar

  • httpmime-4.3.5.jar

    into the libsfolder after Sync with Gradleand Run.

  • httpclient-4.3.5.jar

  • httpmime-4.3.5.jar

    libs之后进入文件夹。Sync with GradleRun

If user 1 jar file - httpmime-4.3.5.jar, I will not get this error.

如果用户 1 jar 文件 - httpmime-4.3.5.jar,我不会收到此错误。

Please help me how to avoid this error & still can use 2 jar files in above also,

请帮助我如何避免此错误,并且仍然可以使用上面的 2 个 jar 文件,

Thanks,

谢谢,

p/s : I use Android Studio version 0.8.6.

p/s:我使用 Android Studio 0.8.6 版。

Error Detail

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

错误:APK 打包过程中出现重复文件 ...\app\build\outputs\apk\app-debug-unaligned.apk 归档路径:META-INF/DEPENDENCIES Origin 1: ...\app\libs\httpclient-4.3 .5.jar 来源 2: ...\app\libs\httpmime-4.3.5.jar

build.gradle

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')
}

UPDATEI changed from compile files('libs/httpmime-4.3.5.jar')to use Maven Link. I got same error again after put 2 maven link together:

UPDATE我改为compile files('libs/httpmime-4.3.5.jar')使用 Maven Link。将 2 个 maven 链接放在一起后,我再次遇到相同的错误:

    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

警告:调试时忽略依赖关系 org.apache.httpcomponents:httpclient:4.4-alpha1,因为它可能与 Android 提供的内部版本冲突。有问题请用jarjar重新打包更改类包

警告:依赖 org.apache.httpcomponents:httpclient:4.4-alpha1 在发布时被忽略,因为它可能与 Android 提供的内部版本冲突。有问题请用jar重新打包更改类包

Please help me fix.

请帮我解决。

SOULITIONI know good answer now by addding these lines will fix Duplicate fileserror :

灵魂我现在知道通过添加这些行来解决Duplicate files错误的好答案:

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'
}

采纳答案by hoomi

You can replace compile files('libs/httpmime-4.3.5.jar')with this compile 'org.apache.httpcomponents:httpmime:4.3.5'.

你可以compile files('libs/httpmime-4.3.5.jar')用这个 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')

此外,您正在复制compile fileTree(include: ['*.jar'], dir: 'libs')已经包含的依赖项compile files('libs/httpmime-4.3.5.jar')

回答by Gaurav Sharma

update your build.gradle and add the following lines

更新您的 build.gradle 并添加以下几行

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.

这将修复此错误。我遇到了同样的错误,这样做修复了它。

回答by Jyoti Prakash Rai

I updated gradle now it's working

我更新了 gradle 现在它正在工作

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

PackagingOptions { 排除 'META-INF/DEPENDENCIES' 排除 'META-INF/LICENSE' 排除 'META-INF/LICENSE.txt' 排除 'META-INF/NOTICE.txt' }

回答by Sadh

Please update this to your build.gradle file.

请将其更新到您的 build.gradle 文件。

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

回答by Nirmal Dhara

add the below code to dependencies

将以下代码添加到依赖项

compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5' compile (group: 'org.apache.httpcomponents' , name: 'httpmime' , version: '4.3.5') { exclude module: 'org.apache.httpcomponents:httpclient' }

编译组:'org.apache.httpcomponents',名称:'httpclient-android',版本:'4.3.5' 编译(组:'org.apache.httpcomponents',名称:'httpmime',版本:'4.3.5 ') { 排除模块:'org.apache.httpcomponents:httpclient' }

now if you run that it will show you why it is telling duplicate may be because of META-INF/NOTICE, META-INF/LICENSE, add that first again run it may show other type. add all like below under android section packagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' }

现在如果你运行它会告诉你为什么它会告诉你重复可能是因为 META-INF/NOTICE、META-INF/LICENSE,首先添加它再次运行它可能会显示其他类型。在 android 部分 PackagingOptions { exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' exclude 'META-INF/LICENSE' }

definitely it will solve your problem.

肯定会解决你的问题。

remove all the dependancy file from the system before build.

在构建之前从系统中删除所有依赖文件。