Retrofit 2.0 非测试版,使用 GsonConverterFactory
Retrofit 2.0 non-beta, using GsonConverterFactory
我正在尝试使用 Retrofit 2.0 的发行版和他们 Retrofit configuration.
上建议的 GsonConverterFactory
问题是 GsonConverterFactory 似乎只适用于 Retrofit 1,而我现在是 Retrofit 2,即使 GsonConverterFactory 处于测试版 2。
这是我的 Gradle 依赖项:
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
我找不到 converter-gson 的非 beta 版本,只是删除 -beta2
并不能解决问题。
当运行这段代码:
import retrofit.GsonConverterFactory;
import retrofit2.Retrofit;
public class Service {
public void getListings()
{
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://www.google.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
Services services = retrofit.create(Services.class);
}
}
我收到这个错误:
addConverterFactory (retrofit2.Converter.Factory) in Builder cannot be applied to (gson.GsonConverterFactory)
除了 运行 retrofit 2 beta 之外还有什么建议吗?
谢谢!
根据改装网站上的文档,他们说您应该使用 com.squareup.retrofit2:converter-gson
在你的build.gradle
中替换
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
与
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
普拉莫德离它很近。这有效:
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
最后需要2.0.0
。
我正在尝试使用 Retrofit 2.0 的发行版和他们 Retrofit configuration.
上建议的 GsonConverterFactory问题是 GsonConverterFactory 似乎只适用于 Retrofit 1,而我现在是 Retrofit 2,即使 GsonConverterFactory 处于测试版 2。
这是我的 Gradle 依赖项:
compile 'com.squareup.retrofit2:retrofit:2.0.0'
compile 'com.google.code.gson:gson:2.6.2'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
我找不到 converter-gson 的非 beta 版本,只是删除 -beta2
并不能解决问题。
当运行这段代码:
import retrofit.GsonConverterFactory;
import retrofit2.Retrofit;
public class Service {
public void getListings()
{
Retrofit retrofit = new Retrofit.Builder()
.baseUrl("http://www.google.com")
.addConverterFactory(GsonConverterFactory.create())
.build();
Services services = retrofit.create(Services.class);
}
}
我收到这个错误:
addConverterFactory (retrofit2.Converter.Factory) in Builder cannot be applied to (gson.GsonConverterFactory)
除了 运行 retrofit 2 beta 之外还有什么建议吗?
谢谢!
根据改装网站上的文档,他们说您应该使用 com.squareup.retrofit2:converter-gson
在你的build.gradle
中替换
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
与
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
普拉莫德离它很近。这有效:
compile 'com.squareup.retrofit2:converter-gson:2.0.0'
最后需要2.0.0
。