commons-logging defines classes that conflict with

2019-01-23 10:56发布

I have updated Android Studio to version 3 and now seems unable to compile my project previously compiled without errors.

The error message is the follow

Error:Error: commons-logging defines classes that conflict with classes now provided by Android. Solutions include finding newer versions or alternative libraries that don't have the same problem (for example, for httpclient use HttpUrlConnection or okhttp instead), or repackaging the library using something like jarjar. [DuplicatePlatformClasses]

The dependencies are

dependencies {
    compile fileTree(include: ['*.jar'], dir: 'libs')
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:27.0.0'
    compile 'com.android.support:design:27.0.0'
    compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
    compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'
    compile 'com.google.firebase:firebase-core:11.4.2'
}

and error seems caused by

compile 'com.google.api-client:google-api-client-android:1.23.0' exclude module: 'httpclient'
compile 'com.google.http-client:google-http-client-gson:1.23.0' exclude module: 'httpclient'

I already use exclude module: 'httpclient' So why It doesn't compile? Is this a bug of Android Studio 3 and\or included com.android.tools.build:gradle:3.0.0 plugin or I'm missing something? With the previous version no problem to compile exactly the same project.

7条回答
啃猪蹄的小仙女
2楼-- · 2019-01-23 11:14

You should replace "compile" with "implementation" as it's deprecated in the latest gradle and exlude "org.apache.httpcomponents" from Google api client libraries:

implementation('com.google.api-client:google-api-client-android:1.23.0') {
    exclude group: 'org.apache.httpcomponents'
}
implementation('com.google.http-client:google-http-client-gson:1.23.0') {
    exclude group: 'org.apache.httpcomponents'
}

this solution was found here: https://developers.google.com/google-apps/activity/v1/quickstart/android

查看更多
甜甜的少女心
3楼-- · 2019-01-23 11:17

Add to build.gradle located in app module

configurations {
    all {
        exclude module: 'httpclient'
    }
}
查看更多
forever°为你锁心
4楼-- · 2019-01-23 11:21

If the problem is with commons-logging then it must be excluded too. Add the following code in app/build.gradle

configurations {
    all {
        exclude module: 'httpclient'
        exclude module: 'commons-logging'
    }
}
查看更多
Bombasti
5楼-- · 2019-01-23 11:24

If you want to continue with async-http then add below following code only in app/build.gradle

configurations {
    all {
        exclude module: 'commons-logging'
    }
}
查看更多
虎瘦雄心在
6楼-- · 2019-01-23 11:27

Got the same issue. I have done below changes

 configurations {
    all{
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents'
    }
}


packagingOptions {
    exclude 'META-INF/LICENSE.txt'
    exclude 'META-INF/LICENSE'
    exclude 'META-INF/NOTICE.txt'
    exclude 'META-INF/NOTICE'
    exclude 'org/apache/http/version.properties'
    exclude 'org/apache/http/client/version.properties'
}
查看更多
我命由我不由天
7楼-- · 2019-01-23 11:29

As 'org.apache.httpcomponents:httpclient:4.3.3' is deprecated after SDKversion 23 so

replace this:

compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'

with

compile 'org.apache.httpcomponents:httpclient:4.3.3'
查看更多
登录 后发表回答