我正在尝试遵循Retrofit的2 教程,但是在这部分代码中有一个GsonConverterFactory显示错误Cannot resolve symbol:
public class ServiceGenerator {
public static final String API_BASE_URL = "http://your.api-base.url";
private static OkHttpClient httpClient = new OkHttpClient();
private static Retrofit.Builder builder =
new Retrofit.Builder()
.baseUrl(API_BASE_URL)
//THIS IS THE LINE WITH ERROR!!!!!!!!!!!!
.addConverterFactory(GsonConverterFactory.create());
public static <S> S createService(Class<S> serviceClass) {
Retrofit retrofit = builder.client(httpClient).build();
return retrofit.create(serviceClass);
}
}
Run Code Online (Sandbox Code Playgroud)
之前我在gradle.build中添加了,我不确定是否应该添加GSON,因为他们说Retrofit 1.9有它但是没有提到Retrofit 2:
dependencies {
// Retrofit & OkHttp
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
}
Run Code Online (Sandbox Code Playgroud)