androidkotlinretrofitmoshi

MoshiConverterFactory is not accessable


I have added both dependencies for Moshi and converter-Moshi but yet MoshiConverterFactory is not accessible and prompting error. Why am I facing this error? I tried to use scalar-converter which worked perfectly but moshi-converter is not.

I have attached the photo of the code where red text clearly shows that converter is not imported.


    // Retrofit
    implementation "com.squareup.retrofit2:retrofit:2.9.0"
    // Retrofit with Moshi Converter
    implementation 'com.squareup.moshi:moshi-kotlin:1.9.3'
    implementation "com.squareup.retrofit2:converter-moshi:2.9.0"
import retrofit2.converter.moshi.MoshiConverterFactory


private val BASE_URL = "https://android-kotlin-fun-mars-server.appspot.com/"

private val moshi = Moshi.Builder()
    .add(KotlinJsonAdapterFactory())
    .build()

private val retrofit = Retrofit.Builder()
    //here MoshiConverterFactory showing errors
    .addConverterFactory(MoshiConverterFactory.create())
    .baseUrl(BASE_URL)
    .build()

enter image description here


Solution

  • You forgot to add the main Moshi dependency. You have added the Kotlin specific dependency, but the main Moshi still is missing. Try adding that and try again.

    implementation 'com.squareup.moshi:moshi:1.12.0'