无法解析符号GsonConverterFactory

时间:2017-07-25 14:27:04

标签: android gradle

如果我尝试使用GsonConvertFactory,我会收到此错误消息:

  

无法解析符号dat <- structure(list(id1 = c(17L, 17L, 17L, 17L, 17L, 17L, 34L, 34L, 34L, 34L, 34L, 34L), id2 = c(13107L, 21463L, 38777L, 21709L, 47766L, 39275L, 16083L, 39475L, 47766L, 2596L, 21137L, 47792L ), prob = c(0.4756982, 0.3724126, 0.3534422, 0.3364623, 0.3364623, 0.3165896, 0.4093785, 0.3892882, 0.3892882, 0.3837562, 0.3762758, 0.3737032), num = c(3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L)), .Names = c("id1", "id2", "prob", "num"), class = "data.frame", row.names = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"))

我正在使用它:

GsonConverterFactory

这是我的gradle文件(Module:app):

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

4 个答案:

答案 0 :(得分:4)

GsonConverterFactory驻留在以下依赖项中,因此请将此作为依赖项添加到build.gradle中。

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

答案 1 :(得分:0)

更改此

compile 'com.google.code.gson:gson:2.7'

到此

compile 'com.google.code.gson:gson:2.8.1'

答案 2 :(得分:0)

你应该将这些库添加到build.gradle文件

编译'com.squareup.retrofit2:converter-gson:2.3.0'   编译'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'
}

答案 3 :(得分:0)

只需添加gson转换器工厂gradle verson 实施'com.squareup.retrofit2:converter-gson:latest.version'