commons-logging defines classes that conflict with classes now provided by Android after Android Studio Update

AndreaF picture AndreaF · Oct 28, 2017 · Viewed 20k times · Source

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.

Answer

Silverstorm picture Silverstorm · Oct 29, 2017

Add to build.gradle located in app module

configurations {
    all {
        exclude module: 'httpclient'
    }
}