2015-04-08 20 views
5

Dodaję zależności w pliku build.gradle.Błąd konstrukcyjny Android Gradle

Mój kod to:

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' 

}

mam błąd:

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 

Jak rozwiązać ten problem. Proszę mi pomóc?

Odpowiedz

8

Możesz spróbować, dodając to w swoim build.gradle (moduł: aplikacja). To rozwiązać mój problem:

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

Mój ostatni build Gradle wygląda następująco:

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: W moim przypadku mam wklejony to 3 słoiki w moim folderze libs. Możesz pobrać i zrobić.

+0

Tak jego pracę @Mohammad Arman – nmkkannan

+0

Tak jego pracy .. –

+0

Dobra odpowiedź! Dziękujemy – Tino

4

I rozwiązać ten problem poprzez zastąpienie następującą linię

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

z tym

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

proszę odwiedzić następujący adres URL, jeśli chcesz wiedzieć więcej o httpclient dla Androida

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

+0

To nie zadziała, jeśli użyjemy klasy MultipartEntity – VVB

2

ja rozwiązać problem za pomocą tego, czy compileSdkVersion jest 19 (w moim przypadku)

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' 

innego jeśli compileSdkVersion wynosi 23 następnie użyć

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

Zamiast dodawania exclude do każdej biblioteki, ty można dodać następującą konfigurację dla wszystkich bibliotek:

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

Jeśli nic nie działa spróbuj to jeden .D efinitely pracować

zastąpić ten

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

z poniżej kod

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