KotlinJsonAdapterFactory 未解析的参考

Fre*_*sXh 8 android kotlin moshi

我正在使用 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" 
Run Code Online (Sandbox Code Playgroud)

这是构建 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()
Run Code Online (Sandbox Code Playgroud)

Ale*_*xTa 31

只需更新到 kotlin 版本即可

implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
Run Code Online (Sandbox Code Playgroud)

https://github.com/square/moshi