2015-04-08 28 views
5

Tôi đang thêm các phụ thuộc vào tệp build.gradle.Android Gradle Build Error

Mã của tôi là:

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' 

}

tôi đã nhận lỗi:

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 

Làm thế nào để giải quyết vấn đề này. Xin hãy giúp tôi?

Trả lời

8

Bạn có thể thử bằng cách thêm điều này vào build.gradle của bạn (Module: app). Nó giải quyết vấn đề của tôi:

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

My thức xây dựng gradle trông giống như:

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: Trong trường hợp của tôi, tôi đã dán này 3 lọ trong thư mục libs của tôi. Bạn có thể tải xuống và làm như vậy.

+0

Ừ làm việc @Mohammad Arman – nmkkannan

+0

Ừ làm việc của nó .. –

+0

Tốt câu trả lời của nó! Cảm ơn bạn – Tino

4

tôi giải quyết vấn đề này bằng cách thay thế dòng sau

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

với điều này

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

Vui lòng truy cập sau URL nếu bạn muốn biết thêm về HttpClient dành cho Android

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

+0

Điều này sẽ không hoạt động nếu chúng tôi sử dụng lớp MultipartEntity – VVB

2

tôi đã giải quyết được phát hành bằng cách sử dụng này nếu compileSdkVersion của bạn là 19 (TRONG TRƯỜNG HỢP CỦA TÔI)

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 compileSdkVersion của bạn là 23 sau đó sử dụng

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

Thay vì thêm exclude cho mỗi thư viện, bạn có thể thêm cấu hình sau cho tất cả các thư viện:

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

Nếu Không có công trình nào thử cái này .d efinitely làm việc

thay thế này

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

với mã dưới đây

dependencies { 
    compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1' 
} 
Các vấn đề liên quan