构建器中的客户端 (com.squareup.okhttp.OkhttpClient) 无法应用于 (okhttp3.OkHttpClient)
Client (com.squareup.okhttp.OkhttpClient) in builder cannot be applied to (okhttp3.OkHttpClient)
我正在尝试使用 Retrofit2 并在 Full 中记录错误,就像在 Retrofit1 中使用
.setLogLevel(RestAdapter.LogLevel.FULL)
我在使用 .client( Okhttp client ) 时遇到错误;这是我的依赖项:
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.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
}
这是我的 java 代码:
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
Interface service = retrofit.create(Interface.class);
我正在使用 Retrofit 2.0.0-beta3,但仍然遇到这个问题。我不能从这里前进。任何帮助表示赞赏。见下图:
下面是我的导入语句:
您的导入语句似乎来自 okhttp
,
检查您的导入:-
必须是import okhttp3.OkHttpClient;
或者你的改造导入一定是错误的..它必须是 retrofit2.Retrofit
[编辑]
他们的测试版似乎有问题,将其恢复为稳定版。
Retrofit 暂时不再处于测试阶段。请改用 com.squareup.retrofit2:retrofit:2.2.0
。
我正在尝试使用 Retrofit2 并在 Full 中记录错误,就像在 Retrofit1 中使用
.setLogLevel(RestAdapter.LogLevel.FULL)
我在使用 .client( Okhttp client ) 时遇到错误;这是我的依赖项:
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.2.0'
compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5'
testCompile 'junit:junit:4.12'
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit:retrofit:2.0.0-beta3'
compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2'
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.2.0'
}
这是我的 java 代码:
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(Api.BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
Interface service = retrofit.create(Interface.class);
我正在使用 Retrofit 2.0.0-beta3,但仍然遇到这个问题。我不能从这里前进。任何帮助表示赞赏。见下图:
下面是我的导入语句:
您的导入语句似乎来自 okhttp
,
检查您的导入:-
必须是import okhttp3.OkHttpClient;
或者你的改造导入一定是错误的..它必须是 retrofit2.Retrofit
[编辑]
他们的测试版似乎有问题,将其恢复为稳定版。
Retrofit 暂时不再处于测试阶段。请改用 com.squareup.retrofit2:retrofit:2.2.0
。