androidkotlinmoshi

KotlinJsonAdapterFactory unresolved reference


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()

Solution

  • Just update to kotlin version

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

    https://github.com/square/moshi