Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot resolve symbol GsonConverterFactory

Tags:

android

gradle

I get this error message if I try to use GsonConvertFactory:

Cannot resolve Symbol GsonConverterFactory

I am using it like this:

    return new Retrofit.Builder()
            .baseUrl(BASE_URL)
            .client(client)
            //.addConverterFactory(MoshiConverterFactory.create())
            .addConverterFactory(GsonConverterFactory.create(gson))
            .build();

This is my gradle file (Module: app):

dependencies {
    ...
    releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.5.1'
    compile 'com.google.code.gson:gson:2.7'
}
like image 937
Olipol Avatar asked Jul 25 '17 14:07

Olipol


2 Answers

GsonConverterFactory resides in following dependency so, add this in your build.gradle as dependency.

compile 'com.squareup.retrofit2:converter-gson:2.3.0'
like image 65
fluffyBatman Avatar answered Sep 21 '22 11:09

fluffyBatman


you shoul add these library to build.gradle file

compile 'com.squareup.retrofit2:converter-gson:2.3.0' compile 'com.squareup.retrofit2:retrofit:2.3.0'

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    compile 'com.android.support:appcompat-v7:25.3.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.squareup.retrofit2:converter-gson:2.3.0'
    compile 'com.squareup.retrofit2:retrofit:2.3.0'
    testCompile 'junit:junit:4.12'
}
like image 30
harun ugur Avatar answered Sep 22 '22 11:09

harun ugur