我已经添加了Moshi和 的两个依赖项converter-Moshi,但仍然MoshiConverterFactory无法访问并提示错误。为什么我会遇到这个错误?我尝试使用标量转换器,它工作得很好,但莫希转换器却不行。
我附上了代码的照片,其中红色文本清楚地表明converter未导入。
// 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"
Run Code Online (Sandbox Code Playgroud)
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()
Run Code Online (Sandbox Code Playgroud)