在我的 Android 中,我将上传文件发送到后端服务器,并考虑使用MultipartEntity HTTP post请求< / strong>即可。在这种情况下,我首先添加了 httpcore 和 httpmime 库,但它给了我一个错误。所以经过一些谷歌搜索我发现 httpclient-android 也必须导入。所以最后我的 build.gradle 文件如下所示。
android {
compileSdkVersion 'Google Inc.:Google APIs:21'
buildToolsVersion '23.0.2'
defaultConfig {
applicationId "com.m.l"
minSdkVersion 14
targetSdkVersion 19
versionCode 69
versionName '2.0.15'
multiDexEnabled true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
productFlavors {
}
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'
}
dexOptions {
incremental true
javaMaxHeapSize "4g"
}
}
dependencies {
compile project(':holoColorPickermaster')
compile project(':qRCodeReaderViewlib')
compile project(':volley')
compile project(':library')
compile 'com.android.support:support-v4:22.2.1'
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.android.support:multidex:'
compile 'org.apache.httpcomponents:httpcore:4.4.4'
compile('org.apache.httpcomponents:httpmime:4.3.6') {
exclude module: 'httpclient'
}
compile 'org.apache.httpcomponents:httpclient-android:4.3.5'
}
但是现在当我运行应用程序时,它会提示我不同的错误。我的错误日志如下,
Error:Execution failed for task ':app:transformClassesWithJarMergingForDebug'.
> com.android.build.api.transform.TransformException: java.util.zip.ZipException: duplicate entry: org/apache/http/concurrent/BasicFuture.class
我在网上查找此错误并尝试修复它。但得不到适当的解决方案。发现这是由重复文件引起的。我怎样才能解决这个问题。谢谢和问候。
答案 0 :(得分:0)
如果您有一些不想编译的源,则必须为源声明一个过滤器,而不是为Jar中放置的类文件。类似的东西:
sourceSets {
main {
java {
include 'com/ourcompany/somepackage/activityadapter/**'
include 'com/ourcompany/someotherpackage/**'
exclude 'com/ourcompany/someotherpackage/polling/**'
}
}
}
如果您不想编译这些软件包,此解决方案有效,但如果您想编译它们并从JAR中排除,则可以使用
jar {
exclude('mi/package/excluded/**')
exclude('mi/package/excluded2/**')
}