首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Gradle构建失败- Apache HttpEntity

Gradle构建失败- Apache HttpEntity
EN

Stack Overflow用户
提问于 2015-04-22 04:42:30
回答 2查看 2K关注 0票数 0

当我尝试运行我的应用程序时,我得到了这个错误:

代码语言:javascript
复制
Information:Gradle tasks [:app:assembleDebug]
Warning:Dependency org.apache.httpcomponents:httpclient:4.3.5 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.3.5 is ignored for release 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
:app:preBuild UP-TO-DATE
:app:preDebugBuild UP-TO-DATE
:app:compileDebugNdk UP-TO-DATE
:app:checkDebugManifest
:app:preReleaseBuild UP-TO-DATE
:app:prepareComAndroidSupportAppcompatV72200Library UP-TO-DATE
:app:prepareComAndroidSupportRecyclerviewV72200Library UP-TO-DATE
:app:prepareComAndroidSupportSupportV42200Library UP-TO-DATE
:app:prepareDebugDependencies
:app:compileDebugAidl UP-TO-DATE
:app:compileDebugRenderscript UP-TO-DATE
:app:generateDebugBuildConfig UP-TO-DATE
:app:generateDebugAssets UP-TO-DATE
:app:mergeDebugAssets UP-TO-DATE
:app:generateDebugResValues UP-TO-DATE
:app:generateDebugResources UP-TO-DATE
:app:mergeDebugResources UP-TO-DATE
:app:processDebugManifest UP-TO-DATE
:app:processDebugResources UP-TO-DATE
:app:generateDebugSources UP-TO-DATE
:app:compileDebugJava UP-TO-DATE
:app:preDexDebug UP-TO-DATE
:app:dexDebug UP-TO-DATE
:app:processDebugJavaRes UP-TO-DATE
:app:validateDebugSigning
:app:packageDebug
Error:duplicate files during packaging of APK /Users/.../app/build/outputs/apk/app-debug-unaligned.apk
    Path in archive: META-INF/NOTICE
    Origin 1: /Users/.../.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5/82edcaec6c7b4599eaeaaf11167ceea41db42f33/httpclient-android-4.3.5.jar
    Origin 2: /Users/.../.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpmime/4.3.5/1dd0d38df9c6d21e893f2e52403f1cd99e91cd81/httpmime-4.3.5.jar
You can ignore those files in your build.gradle:
    android {
      packagingOptions {
        exclude 'META-INF/NOTICE'
      }
    }
Error:Execution failed for task ':app:packageDebug'.
> Duplicate files copied in APK META-INF/NOTICE
    File 1: /Users/.../.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5/82edcaec6c7b4599eaeaaf11167ceea41db42f33/httpclient-android-4.3.5.jar
    File 2: /Users/.../.gradle/caches/modules-2/files-2.1/org.apache.httpcomponents/httpclient-android/4.3.5/82edcaec6c7b4599eaeaaf11167ceea41db42f33/httpclient-android-4.3.5.jar
Information:BUILD FAILED
Information:Total time: 2.754 secs
Information:2 errors
Information:2 warnings
Information:See complete output in console

这是我的build.gradle:

代码语言:javascript
复制
apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "..."
        minSdkVersion 14
        targetSdkVersion 22
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.0.0'
    compile 'com.android.support:support-v4:22.0.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    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'
    }

}

我只想导入以下库:

代码语言:javascript
复制
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.ContentBody;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.entity.mime.content.StringBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.json.JSONObject;

所以我可以运行下面的代码:

代码语言:javascript
复制
       String sendProfileData = getResources().getString(R.string.URL);

        DefaultHttpClient client = new DefaultHttpClient();
        HttpPost post = new HttpPost(sendProfileData);

        MultipartEntity mpEntity = new MultipartEntity();

        try {
            mpEntity.addPart("first_name", new StringBody("Jay"));
            mpEntity.addPart("last_name", new StringBody("Shmidt"));
            ...
        }
        ...

这里到底出了什么问题-我真的需要删除或替换jar文件吗?为什么gradle不处理这件事?

任何建议都会很有帮助。提前感谢!

EN

回答 2

Stack Overflow用户

发布于 2015-04-22 05:26:58

更新:我从这篇文章中得到了答案

Android Gradle plugin 0.7.0: "duplicate files during packaging of APK"

代码语言:javascript
复制
android {
    packagingOptions {
        exclude 'META-INF/DEPENDENCIES.txt'
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/dependencies.txt'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/LGPL2.1'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/notice.txt'
    }
}
票数 1
EN

Stack Overflow用户

发布于 2015-09-02 11:19:16

这在Android Studio中没有问题,只是你的系统需要互联网连接

jar文件只是扩展了类,按MultipartEntity

  • Than

  • 键,然后单击find jar on

  • MultipartEntity

  • Than httpmime-4.0-alpha4.jar

  • Than

  • 选择httpmime-4.0-alpha4.jar

  • Than右键单击项目added

  • Finally打开模块设置依赖项选项卡中的图标单击右侧的+图标<

  • >H115>然后单击文件依赖项选择http:mime file file build

  • <代码>H218><代码>G219>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/29782727

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档