放入2个jar文件时出现此错误 Duplicate files during packaging of APK app-debug-unaligned.apk
:
-
httpclient-4.3.5.jar
-
httpmime-4.3.5.jar
进入 Sync with Gradle
和 Run
之后的 libs
文件夹 .
如果用户1个jar文件 - httpmime-4.3.5.jar
,我不会收到此错误 .
请帮我如何避免这个错误,还可以使用上面的2个jar文件,
谢谢,
p / s:我使用Android Studio版本0.8.6 .
Error Detail
错误:在APK ... \ app \ build \ outputs \ apk \ app-debug-unaligned.apk包装过程中重复文件存档中的路径:META-INF / DEPENDENCIES原点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
我从 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'
这是警告
警告:依赖org.apache.httpcomponents:httpclient:4.4-alpha1因调试而被忽略,因为它可能与Android提供的内部版本冲突 . 如果出现问题,请使用jarjar重新打包以更改类包警告:依赖org.apache.httpcomponents:httpclient:4.4-alpha1因发布而被忽略,因为它可能与Android提供的内部版本冲突 . 如有问题,请用jar重新包装以更改课程包
请帮我解决 .
SOULITION 我现在知道很好的答案,添加这些行将修复 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'
}
5 回答
您可以使用此编译
'org.apache.httpcomponents:httpmime:4.3.5'
替换compile files('libs/httpmime-4.3.5.jar')
.此外,您正在复制依赖项
compile fileTree(include: ['*.jar'], dir: 'libs')
已包含compile files('libs/httpmime-4.3.5.jar')
更新build.gradle并添加以下行
这将解决此错误 . 我得到了同样的错误,修复它 .
请将其更新到build.gradle文件 .
我现在更新了gradle它正在工作
packagingOptions {exclude'META-INF / DEPENDENCIES'排除'META-INF / LICENSE'排除'META-INF / LICENSE.txt'排除'META-INF / NOTICE.txt'}
将以下代码添加到依赖项中
编译组:'org.apache.httpcomponents',名称:'httpclient-android',版本:'4.3.5'compile(group:'org.apache.httpcomponents',name:'httpmime',version:'4.3.5 '){exclude module:'org.apache.httpcomponents:httpclient'}
现在如果你运行它会告诉你为什么它告诉重复可能是因为META-INF / NOTICE,META-INF / LICENSE,再加上它再次运行它可能会显示其他类型 . 在android部分下添加所有内容如下所示packageOptions {exclude'META-INF / LICENSE.txt'排除'META-INF / NOTICE'排除'META-INF / LICENSE'}
绝对会解决你的问题 .
在构建之前从系统中删除所有依赖性文件 .