我在一个项目中使用OkHhttp和Retrofit。我有一个'RestClient'Java类,它正在构建OkHttp和改造客户端,当我在类中使用Request
以下代码正在编译,没有问题:
private OkHttpClient createOkHttpClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.addNetworkInterceptor(chain -> {
int flags = Base64.NO_WRAP | Base64.URL_SAFE;
String header = calculateHeader()
Request request = chain.request().newBuilder().addHeader("Authorization", header).build();
return chain.proceed(request);
});
return builder.build();
}
但是,如果我添加了一种基于Request
来计算标题的方法,则会失败
private OkHttpClient createOkHttpClient() {
OkHttpClient.Builder builder = new OkHttpClient.Builder().connectTimeout(CONNECT_TIMEOUT, TimeUnit.SECONDS)
.writeTimeout(WRITE_TIMEOUT, TimeUnit.SECONDS)
.readTimeout(READ_TIMEOUT, TimeUnit.SECONDS)
.addNetworkInterceptor(chain -> {
int flags = Base64.NO_WRAP | Base64.URL_SAFE;
String header = calculateHeader(chain.request())
Request request = chain.request().newBuilder().addHeader("Authorization", header).build();
return chain.proceed(request);
});
return builder.build();
}
private String calculateHeader(Request request) {/** ... */ }
然后我在Kotlin编译器中遇到以下错误:
error: cannot access Request class file for okhttp3.Request not found. Consult the following stack trace for details
不幸的是,没有堆栈跟踪。
我尝试禁用Proguard和R8,但没有成功,仍然存在相同的错误,并且使此消息消失的唯一方法是从方法中删除Request
参数。
我在那里缺少什么?