android - gradle中的依赖冲突
问题描述
我在改造中遇到了这个冲突错误:
java.lang.RuntimeException:在模块 gson-2.8.5.jar (com.google.code.gson:gson:2.8.5) 和 pubnub-gson-4.19.0-all 中发现重复的类 com.google.gson.DefaultDateTypeAdapter .jar (pubnub-gson-4.19.0-all.jar)
这是我的所有依赖项的 gradle 文件:
apply plugin: 'com.android.application'
android {
compileSdkVersion 28
// buildToolsVersion '27.0.3'
// useLibrary 'org.apache.http.legacy'
packagingOptions {
exclude 'META-INF/DEPENDENCIES'
exclude 'META-INF/LICENSE'
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/license.txt'
exclude 'META-INF/NOTICE'
exclude 'META-INF/NOTICE.txt'
exclude 'META-INF/notice.txt'
exclude 'META-INF/ASL2.0'
}
defaultConfig {
applicationId "com.chaufferapplication"
minSdkVersion 19
targetSdkVersion 28
multiDexEnabled true
versionCode 38
versionName "4.6.6.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
}
lintOptions {
// Returns whether lint should be quiet (for example, not write informational messages such as paths to report files written)
quiet true
// Whether lint should set the exit code of the process if errors are found
abortOnError false
// Returns whether lint will only check for errors (ignoring warnings)
ignoreWarnings true
// Returns whether lint should check for fatal errors during release builds. Default is true.
// If issues with severity "fatal" are found, the release build is aborted.
checkReleaseBuilds false
}
}
dependencies {
implementation files('libs/json-20140107.jar')
implementation files('libs/mobiprobe7.0.jar')
implementation files('libs/pubnub-gson-4.19.0-all.jar'){
configurations {
compile.exclude module: 'okhttp3'
}
}
annotationProcessor files('libs/pubnub-gson-4.19.0-all.jar'){
configurations {
compile.exclude module: 'okhttp3'
}
}
implementation files('libs/test.jar')
implementation files('libs/WebSocket.jar')
implementation 'com.mikhaellopez:circularimageview:3.2.0'
implementation 'com.google.android.gms:play-services-location:17.0.0'
implementation 'com.google.android.gms:play-services-places:17.0.0'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
implementation 'com.google.android.gms:play-services-analytics:17.0.0'
implementation 'com.github.bumptech.glide:glide:4.9.0'
implementation 'androidx.appcompat:appcompat:1.0.0'
implementation 'com.google.android.material:material:1.0.0'
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
implementation 'com.lsjwzh:materialloadingprogressbar:0.5.8-RELEASE'
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'androidx.cardview:cardview:1.0.0'
implementation "se.emilsjolander:stickylistheaders:2.7.0"
implementation 'me.grantland:autofittextview:0.2.+'
implementation 'org.droidparts:droidparts:2.9.6'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'me.tankery.lib:circularSeekBar:1.1.7'
implementation 'ch.acra:acra:4.9.0'
implementation 'com.google.maps.android:android-maps-utils:0.5+'
implementation 'androidx.multidex:multidex:2.0.0'
implementation 'com.googlecode.libphonenumber:libphonenumber:8.2.0'
implementation 'me.biubiubiu.justifytext:library:1.1'
implementation 'org.jsoup:jsoup:1.11.3'
implementation 'com.google.firebase:firebase-core:17.0.1'
implementation 'com.google.firebase:firebase-messaging:19.0.1'
implementation 'com.google.firebase:firebase-crash:16.2.1'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
//Retrofit
implementation "com.squareup.retrofit2:retrofit:2.6.1"
// implementation "com.squareup.retrofit2:converter-gson:2.6.1"
implementation "com.squareup.retrofit2:converter-scalars:2.6.1"
}
apply plugin: 'com.google.gms.google-services'
在运行该应用程序时,我遇到了改造和 PubNub 冲突的错误。有人对此有解决方案吗?我也尝试过排除 okhttp3 ,但它仍然无法正常工作并引发错误。Retrofit 是一个依赖项,而 pubnub 是一个 jar 文件,两者都将 okhttp3 作为通用模块,并且由于具有相同的模块而发生冲突
解决方案
您是否尝试在 build.gradle 中添加强制解析策略?
configurations.all {
resolutionStrategy.force 'com.squareup.okhttp3:okhttp:4.3.1'
}
替换所需版本的 okhttp 库。
推荐阅读
- php - 引导崩溃:显示一个隐藏另一个
- ssl - 如何通过 SSL/TLS 连接 Thingsboard 和 Thingsboard 物联网网关?
- php - 检查队列返回状态
- jakarta-ee - 如何在生产中禁用 swagger-ui(Thorntail)?
- ssl - Websphere trust.p12 vs cacert 存储
- if-statement - MultiWayIf 和经典守卫有什么区别?
- sql - JPARepository findAllByUsername 返回 null 但数据存在
- c# - 用 3D 高斯拟合星光
- reactjs - 发布的数据无法用 reactjs 显示
- xml - XSLT "Choose-When" 设置变量给出不同的结果