Java NoClassDefFoundError:Square日志拦截器v3.12.0 问题
将添加到我的Kotlin应用程序后,我遇到以下错误,我认为可能是由于番石榴依赖冲突造成的。我也去过Square的图书馆 错误 改装 尝试的解决方案Java NoClassDefFoundError:Square日志拦截器v3.12.0 问题,java,android,kotlin,okhttp3,Java,Android,Kotlin,Okhttp3,将添加到我的Kotlin应用程序后,我遇到以下错误,我认为可能是由于番石榴依赖冲突造成的。我也去过Square的图书馆 错误 改装 尝试的解决方案 重建Jar工件 重建项目 使IntelliJ缓存无效并重新启动IDE 正在重新同步渐变文件 明确定义guava和com.google.api库 从图书馆中排除较旧版本的番石榴。() 格雷德尔先生 在我的例子中,我安装了日志拦截器(3.13.1) com.squareup.okhttp3 日志拦截器 3.13.1 它使用了okhttp(3.13.1
在我的例子中,我安装了日志拦截器(3.13.1)
com.squareup.okhttp3
日志拦截器
3.13.1
它使用了okhttp(3.13.1)
com.squareup.okhttp3
okhttp
3.13.1
以及我的改装版(2.5.0)
com.squareup.2
改造
2.5.0
它使用了okhttp(3.12.0)
com.squareup.okhttp3
okhttp
3.12.0
由于顺序(或smth),okhttp依赖于日志侦听器。
我猜okhttp(3.12.0)与日志拦截程序(3.13.1)不兼容我发现了同样的问题,只是将日志拦截程序添加到gradle中会使应用程序崩溃 我尝试了不同的版本:3.13.1和3.14.2,但目前似乎只有4.0.0-alpha2解决了这个问题:
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.0-alpha02'
您是如何运行这个程序的?它正在IDE(IntelliJ)中运行,用于开发和测试。对于生产,它内置在一个Jar文件中。谢谢!如果这个问题再次出现,我将测试这个解决方案。请将问题向上投票,以便其他人可以轻松找到您的解决方案。
buildscript {
ext.kotlin_version = '1.3.11'
ext.junitJupiterVersion = '5.3.2'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.0.3'
}
}
plugins {
id 'java'
id 'org.jetbrains.kotlin.jvm' version '1.2.51'
}
version '1.0-SNAPSHOT'
sourceCompatibility = 1.8
repositories {
mavenCentral()
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8"
testImplementation group: 'junit', name: 'junit', version: '5.3.2'
// JUnit Jupiter API and TestEngine implementation
testImplementation("org.junit.jupiter:junit-jupiter-api:${junitJupiterVersion}")
testRuntime("org.junit.jupiter:junit-jupiter-engine:${junitJupiterVersion}")
testImplementation "org.assertj:assertj-core:3.11.1"
// To avoid compiler warnings about @API annotations in JUnit code
testCompileOnly 'org.apiguardian:apiguardian-api:1.0.0'
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
implementation 'com.squareup.retrofit2:adapter-rxjava:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.12.0'
implementation 'io.reactivex.rxjava2:rxjava:2.2.4'
implementation 'com.google.firebase:firebase-admin:6.6.0'
implementation 'com.google.apis:google-api-services-youtube:v3-rev206-1.25.0'
}
compileKotlin {
kotlinOptions.jvmTarget = "1.8"
}
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}
package utils
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.logging.HttpLoggingInterceptor.Level
import retrofit2.Retrofit
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory
import utils.Enums.EnvironmentType.PRODUCTION
import utils.EnvironmentType.environmentType
object Retrofit {
val eventRegistryRetrofit: Retrofit
val youTubeRetrofit: Retrofit
init {
eventRegistryRetrofit = retrofitBuilder(EVENTREGISTRY_BASE_URL)
youTubeRetrofit = retrofitBuilder(YOUTUBE_BASE_URL)
}
/**
* Build Retrofit object based on source.
*/
fun retrofitBuilder(baseUrl: String): Retrofit {
val debugOkHttpClient =
okhttp3.OkHttpClient.Builder().addInterceptor(HttpLoggingInterceptor().setLevel(Level.BASIC)).build()
return Retrofit.Builder().addConverterFactory(GsonConverterFactory.create())
.baseUrl(baseUrl)
.client(if (environmentType == PRODUCTION) OkHttpClient() else debugOkHttpClient)
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build()
}
}
...
dependencies {
implementation "com.google.guava:guava:27.0.1-jre"
implementation ("com.google.api:gax:1.33.1") {
exclude group: "com.google.guava", module: "guava"
}
implementation ("com.google.api:gax-grpc:1.33.1") {
exclude group: "com.google.guava", module: "guava"
}
...
implementation ('com.squareup.okhttp3:logging-interceptor:3.12.0') {
exclude group: "com.google.guava", module: "guava"
}
...
}
...
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>3.13.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.13.1</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.5.0</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.12.0</version>
</dependency>
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
implementation 'com.squareup.okhttp3:logging-interceptor:4.0.0-alpha02'