GsonConverter未解决

时间:2016-04-01 10:19:34

标签: java android gradle gson retrofit

我在build.gradle文件中添加了此内容。

build.gradle

  compile 'com.squareup.retrofit2:retrofit:2.0.0-beta4'
  compile 'com.squareup.retrofit2:converter-gson:2.0.0-beta4

但仍然没有解决改装2的GsonConverter。

3 个答案:

答案 0 :(得分:2)

为什么不使用稳定的版本?

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

答案 1 :(得分:1)

您还必须在gradle依赖项中添加gson

compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.squareup.retrofit2:converter-gson:2.0.0' 
compile 'com.google.code.gson:gson:2.6.2' // this should also be there

并创建这样的改造实例:

public static final String BASE_URL = "http://api.example.com/";
Retrofit retrofit = new Retrofit.Builder()
    .baseUrl(BASE_URL)
    .addConverterFactory(GsonConverterFactory.create())
    .build();

答案 2 :(得分:1)

嘿,即使我遇到同样的问题,添加以下行也无效。

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

然后我去maven资源库下载了jar并粘贴在android studio的libs文件夹中。链接如下:

[https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22converter-gson%22][1]

然后将以下行添加到gradle

compile files('libs/converter-gson-2.0.1.jar')
    compile 'com.google.code.gson:gson:2.6.2'