KotlinJsonAdapterFactory unresolved reference
Asked Answered
G

1

8

I am building an Android app in Kotlin, and I'm using Retrofit for the API calls, and I'm also using Moshi. But when building Moshi it says KotlinJsonAdapteryFactory - unresolved reference, and I can't use Moshi since it gives me an error in this line. Any idea of why is this happening? These are my Moshi dependencies:

    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" 

and this is the code for building Moshi and 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()
Guide answered 19/11, 2021 at 14:23 Comment(0)
F
33

Just update to kotlin version

implementation("com.squareup.moshi:moshi-kotlin:1.14.0")

https://github.com/square/moshi

Fraud answered 19/11, 2021 at 14:36 Comment(1)
Okay, It worked!Guide

© 2022 - 2024 — McMap. All rights reserved.