Tôi đang cố gắng làm theo Retrofit của 2 tutorial, nhưng trên phần này của mã có một GsonConverterFactory
hiển thị lỗi Cannot resolve symbol
:Retrofit 2 ví dụ hướng dẫn, nhưng lỗi hiển thị GsonConverterFactory "Không thể giải quyết biểu tượng"
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);
}
}
Trước đây tôi thêm vào trong gradle.build của tôi, tôi không chắc chắn nếu tôi nên thêm GSON kể từ khi họ nói Retrofit 1.9 có nó nhưng không được đề cập về Retrofit 2:
dependencies {
// Retrofit & OkHttp
compile 'com.squareup.retrofit:retrofit:2.0.0-beta2'
}
Bạn không thể sử dụng GsonConverterFactory trong Retrofit 2, vì nó chỉ áp dụng cho trang bị thêm 1 –
tôi đang làm theo hướng dẫn này: http://wiki.workassis.com/android-retrofit-2-1-http-client/ –
Tham khảo http://stackoverflow.com/a/41015925/3470479 – PrakhaRaM