gradlekotlinimportgsonfuel

How can I fix Unresolved reference: Gson?


I'm trying to follow a tutorial about Android application. I'm using an dependency Fuel (which has a dependency to com.google.Gson deserializer). But Gson() is not imported by IDE.

I've tried to specify lower version of gson. I've re-synchronized all project gradle. I've tried to write import manually (import com.google.gson.Gson), but I can't use Gson() constructor. I've read manual about using Gson, but nothing seem to be changed. It's always the same way. Call constructor Gson() and after all static method... Gson().fromJson(....)

Here is section in my build.gradle (module:app)

    // Fuel HTTP Client
    implementation 'com.github.kittinunf.fuel:fuel:2.2.0'
    implementation 'com.github.kittinunf.fuel:fuel-android:2.2.0'
    implementation 'com.github.kittinunf.fuel:fuel-gson:2.2.0'

and In code, I'm using in ArticleDataProvider.kt:

class WikipediaDataDeserializer : ResponseDeserializable<WikiResults> {

        override fun deserialize(reader: Reader): WikiResults? {
            return Gson().fromJson(reader, WikiResults::class.java)
        }
}

Normally, I would to have Gson() recognised by IDE and I wound be able to call .fromJson() normally. Gradle was downloaded properly. (I don't have any message error about).

enter image description here


Solution

  • Using this Lib in your gradle:

    dependencies{
      implementation 'com.google.code.gson:gson:2.8.2'
    }