MoshiConverterFactory is not accessable
Asked Answered
T

3

6

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

Timorous answered 6/6, 2021 at 7:37 Comment(0)
W
6

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'
Watercool answered 6/6, 2021 at 7:47 Comment(1)
This is not working for me still. //network implementation "com.squareup.retrofit2:retrofit:$retrofit" implementation 'com.squareup.moshi:moshi-kotlin:1.13.0' implementation "com.squareup.retrofit2:converter-moshi:$moshi" implementation "com.squareup.moshi:moshi:$moshiConvertor"Modest
D
4

You Must make sure that you have added all dependencies

//moshi
implementation "com.squareup.moshi:moshi-kotlin:1.14.0"
implementation 'com.squareup.moshi:moshi:1.14.0'
kapt "com.squareup.moshi:moshi-kotlin-codegen:1.14.0"

//retrofit
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-moshi:2.9.0'
implementation("com.squareup.okhttp3:okhttp:4.9.0")
implementation("com.squareup.okhttp3:logging-interceptor:4.9.0")`
Debi answered 14/12, 2022 at 12:8 Comment(0)
N
2

You need to add converter moshi dependency

implementation ("com.squareup.retrofit2:converter-moshi:2.11.0")
Needlefish answered 9/5 at 8:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.