摇篮构建失败 - 阿帕奇HttpEntity [英] Gradle build failed - Apache HttpEntity

查看:313
本文介绍了摇篮构建失败 - 阿帕奇HttpEntity的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I get this error when I try to run my application:

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:

Here is my build.gradle:

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

}

我只是想导入以下库:

I simply want to import the following libraries:

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;

这样我就可以运行下面的code:

so I can run the following code:

       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文件?为什么不摇篮趁着这个照顾?

What exactly is wrong here - Do I actually need to delete or replace jar files? Why isn't gradle taking care of this?

任何意见将是真正的帮助。在此先感谢!

Any advice would be really helpful. Thanks in advance!

推荐答案

这就是Android Studio中只有你的系统需要互联网连接。

Thats not problem in Android Studio only your system require internet connection


  1. 只需扩展类MultipartEntity

  2. 比preSS Alt + Enter键

  3. 点击比上找到网页的jar

  4. 选择httpmime-4.0-alpha4.jar

  5. 比右键点击项目结构

  6. 单击打开模块设置

  7. 在依赖选项卡点击+在右侧的图标

  8. 比点击文件相关性选择http:MIME文件添加

  9. 最后建项目

这篇关于摇篮构建失败 - 阿帕奇HttpEntity的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆