And*_*eaF 47 android android-studio android-gradle-plugin android-studio-3.0 android-gradle-3.0
我已将Android Studio更新为版本3,现在似乎无法编译我之前编译的项目而没有错误.
错误消息如下
错误:错误:commons-logging定义与Android现在提供的类冲突的类.解决方案包括查找没有相同问题的更新版本或替代库(例如,对于httpclient使用HttpUrlConnection或okhttp),或者使用jarjar之类的东西重新打包库.[DuplicatePlatformClasses]
依赖是
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'
}
Run Code Online (Sandbox Code Playgroud)
和错误似乎是由
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'
Run Code Online (Sandbox Code Playgroud)
我已经使用了exclude module: 'httpclient'
为什么它不编译?这是Android Studio 3和\或包含com.android.tools.build:gradle:3.0.0插件的错误还是我遗漏了什么?使用以前的版本编译完全相同的项目没有问题.
Sil*_*orm 57
添加到build.gradle位于app模块中
configurations {
all {
exclude module: 'httpclient'
}
}
Run Code Online (Sandbox Code Playgroud)
srs*_*srs 30
如果问题在于公共日志记录,那么它也必须被排除.在app/build.gradle中添加以下代码
configurations {
all {
exclude module: 'httpclient'
exclude module: 'commons-logging'
}
}
Run Code Online (Sandbox Code Playgroud)
有同样的问题。我做了以下更改
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'
}
Run Code Online (Sandbox Code Playgroud)
在终端的项目文件夹中运行:
./gradlew app:dependencies > dependencies.txt
Run Code Online (Sandbox Code Playgroud)
然后检查dependencies.txt以查找谁在使用冲突的依赖项并采取相应措施(检查更新,摆脱它,或按照@Silverstorm的建议使用排除项)
小智 5
您应将“ 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'
}
Run Code Online (Sandbox Code Playgroud)
在此处找到此解决方案:https : //developers.google.com/google-apps/activity/v1/quickstart/android
| 归档时间: |
|
| 查看次数: |
15477 次 |
| 最近记录: |