commons-logging定义了与Android Studio Update之后Android现在提供的类冲突的类

时间:2021-12-10 20:55:20

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

我已将Android Studio更新到版本3,现在似乎无法编译我之前编译的项目而没有错误。

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]

错误:错误:commons-logging定义与Android现在提供的类冲突的类。解决方案包括查找没有相同问题的更新版本或替代库(例如,对于httpclient使用HttpUrlConnection或okhttp),或者使用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.

我已经使用了exclude模块:'httpclient'那么为什么它不能编译?这是Android Studio 3和\或包含com.android.tools.build:gradle:3.0.0插件的错误还是我遗漏了什么?使用以前的版本编译完全相同的项目没有问题。

7 个解决方案

#1


44  

Add to build.gradle located in app module

添加到app模块中的build.gradle

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

#2


20  

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

如果问题在于公共日志记录,那么它也必须被排除。在app / build.gradle中添加以下代码

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

#3


3  

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

您应该将“compile”替换为“implementation”,因为它已在最新的gradle中弃用,并从Google api客户端库中排除“org.apache.httpcomponents”:

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

此解决方案可在此处找到:https://developers.google.com/google-apps/activity/v1/quickstart/android

#4


2  

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)

然后检查dependencies.txt以查找谁正在使用冲突依赖项并相应地执行操作(检查更新,删除它,或使用@Silverstorm建议的排除)

#5


1  

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

#6


1  

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

如果您想继续使用async-http,请仅在app / build.gradle中添加以下代码

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

#7


0  

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

由于'org.apache.httpcomponents:httpclient:4.3.3'在SDKversion 23之后被弃用了

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'

#1


44  

Add to build.gradle located in app module

添加到app模块中的build.gradle

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

#2


20  

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

如果问题在于公共日志记录,那么它也必须被排除。在app / build.gradle中添加以下代码

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

#3


3  

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

您应该将“compile”替换为“implementation”,因为它已在最新的gradle中弃用,并从Google api客户端库中排除“org.apache.httpcomponents”:

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

此解决方案可在此处找到:https://developers.google.com/google-apps/activity/v1/quickstart/android

#4


2  

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)

然后检查dependencies.txt以查找谁正在使用冲突依赖项并相应地执行操作(检查更新,删除它,或使用@Silverstorm建议的排除)

#5


1  

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

#6


1  

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

如果您想继续使用async-http,请仅在app / build.gradle中添加以下代码

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

#7


0  

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

由于'org.apache.httpcomponents:httpclient:4.3.3'在SDKversion 23之后被弃用了

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'