我正在使用Kotlin构建Android应用程序,并使用Retrofit进行API调用,同时还使用Moshi。但是在构建Moshi时,它会提示“KotlinJsonAdapteryFactory - 未解决的引用”,并且我无法使用Moshi,因为它在此行中给出了一个错误。您有任何想法为什么会发生这种情况吗?
这些是我的Moshi依赖项:
implementation("com.squareup.moshi:moshi:1.12.0")
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.12.0"
implementation "com.squareup.retrofit2:converter-moshi:2.5.0"
以下是构建 Moshi 和 Retrofit 的代码:
private val moshi: Moshi = Moshi.Builder().addLast(KotlinJsonAdapterFactory()).build()
val retrofit: Retrofit = Retrofit.Builder()
.client(getLoggingHttpClient())
.baseUrl(BASE_URL)
.addConverterFactory(MoshiConverterFactory.create(moshi))
.build()