Issue
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
From Moshi's github documentation:
The reflection adapter requires the following additional dependency
implementation("com.squareup.moshi:moshi-kotlin:1.12.0")
You have missed the dependency posted above, just add it to you gradle file and resync your project.
Answered By - AlexTa
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.