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

陌路散爱 提交于 2019-11-27 21:47:13

Add to build.gradle located in app module

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

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

Run in terminal, inside project folder:

./gradlew app:dependencies > dependencies.txt

Then check dependencies.txt to find who is using conflictive dependencies and act accordingly (check for updates, get rid of it, or use exclude as suggested by @Silverstorm)

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

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

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

configurations {
    all {
        exclude module: 'commons-logging'
    }
}

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'

I removed commons-logging as suggested above, of course it crashed on some phone with Fatal Exception: java.lang.NoClassDefFoundError: Failed resolution of: Lorg/apache/commons/logging/LogFactory;. How can Android claim the commons-logging is conflicting with Android API when the Android API doesn't contain any of those classes?!? There is no org.apache.commons.logging at https://developer.android.com/reference/packages :facepalm:

I've added back implementation 'commons-logging:commons-logging:1.0.4' to the build.gradle - Android Studio underlines it with red but gradle compiles happily. :facepalm:

Android :triple_facepalm:

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!