Sho*_*lid 4 android kotlin retrofit moshi
我已经添加了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)
您忘记添加主要的 Moshi 依赖项。您已经添加了 Kotlin 特定的依赖项,但主要的 Moshi 仍然缺失。尝试添加它并重试。
implementation 'com.squareup.moshi:moshi:1.12.0'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4023 次 |
| 最近记录: |