简体   繁体   中英

Android Gradle Build Error

I am adding dependencies in build.gradle file.

My code is :

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:21.0.3'
compile 'com.google.android.gms:play-services:6.1.11'
compile 'org.apache.httpcomponents:httpmime:4.4.1'
compile 'org.apache.httpcomponents:httpcore:4.4.1'
compile 'org.apache.httpcomponents:httpclient:4.4.1'

}

I got error :

Warning:Dependency org.apache.httpcomponents:httpclient:4.4.1 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.1 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.1 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

Warning:Dependency org.apache.httpcomponents:httpclient:4.4.1 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

How to solve this problem. Please help me ?

You can try by adding this in your build.gradle (Module: app). It solved my issue:

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

My final build gradle looks like:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 21
    buildToolsVersion "21.1.2"

    defaultConfig {
        applicationId "info.androidhive.camerafileupload"
        minSdkVersion 19
        targetSdkVersion 21
    }

    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    packagingOptions{
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/LICENSE'
    }
}

dependencies {
    compile 'com.android.support:appcompat-v7:21.0.3'
    compile files('libs/httpclient-4.3.6.jar')
    compile files('libs/httpcore-4.3.3.jar')
    compile files('libs/httpmime-4.3.6.jar')
}

NB: In my case I have pasted this 3 jars in my libs folder. You can download and do so.

I solved this issue by replacing following line

compile "org.apache.httpcomponents:httpclient:4.4.1"

with this

compile "org.apache.httpcomponents:httpclient-android:4.3.5.1"

Please visit following URL if you want to know more about HttpClient for Android

https://hc.apache.org/httpcomponents-client-4.3.x/android-port.html

I solved the Issue by Using This if your compileSdkVersion is 19(IN MY CASE)

compile ('org.apache.httpcomponents:httpmime:4.3'){
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile ('org.apache.httpcomponents:httpcore:4.4.1'){
    exclude group: 'org.apache.httpcomponents', module: 'httpclient'
}
compile 'commons-io:commons-io:1.3.2'

else if your compileSdkVersion is 23 then use

android {
useLibrary 'org.apache.http.legacy'
packagingOptions {
    exclude 'META-INF/DEPENDENCIES'
    exclude 'META-INF/NOTICE'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/NOTICE.txt'
    }
}

Instead of adding exclude to each library, you can add following configuration for all libraries:

configurations {
    all*.exclude group: 'org.apache.httpcomponents',module: 'httpclient'
}

If Nothing works try this one .definitely work

replace this

 dependencies {
......
.......
    compile 'org.apache.httpcomponents:httpclient:4.4.1'
}

with below code

dependencies {
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM