Java 为什么我不能调试Proxy.newProxyInstance方法?
我正在安卓系统上使用改型 我定义了一个服务Java 为什么我不能调试Proxy.newProxyInstance方法?,java,android,retrofit2,Java,Android,Retrofit2,我正在安卓系统上使用改型 我定义了一个服务GitHubService public interface GithubService { @GET("users/{user}") Call<ResponseBody> fetchUserInfo(@Path("user") String user); } 我在if(method.getDeclaringClass()==Object.class)行进行调试,但是它崩溃了。我不知道它为什么会崩溃 编辑 我测试了几个设
GitHubService
public interface GithubService {
@GET("users/{user}")
Call<ResponseBody> fetchUserInfo(@Path("user") String user);
}
我在if(method.getDeclaringClass()==Object.class)
行进行调试,但是它崩溃了。我不知道它为什么会崩溃
编辑
我测试了几个设备
- Nexus 6P Android 8.0:调试时崩溃
- 小米6安卓8.1:调试时崩溃
- OnePlus 3 Android 8.0:调试时崩溃
- Nexus6pAndroid 7.0:调试时运行良好
- Oppo安卓6.0:调试时运行良好
- 三星S4安卓5.0:调试时运行良好
private RestApiStack() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// preview requests
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(interceptor);
}
OkHttpClient client = builder.build();
Retrofit retrofit = (new Retrofit.Builder())
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(/*...*/)
.build();
api = retrofit.create(ApiStack.class);
}
依赖项:
implementation "com.squareup.okhttp3:logging-interceptor:3.9.1"
implementation "com.squareup.okhttp3:okhttp:3.11.0"
由于崩溃发生在Android 8及更高版本上,我想这与该版本对后台运行的应用程序的限制有关 我想,由于您的调试工作,应用程序在后台保持活动的时间太长,导致系统最终将其杀死
然而,日志中应该有关于这一点的内容。如果您从Logcat窗口中删除任何过滤器,您可能会看到它。您可以提供Logcat吗?@jeelvankhee没有崩溃日志。我只是想调试改装并了解它是如何工作的。关键是
拦截器
,按照我向您展示的方式使用它。运行应用程序时,请尝试在logcat控制台中编写okhttp
。您可以在非常简单的情况下尝试上面的代码。实际上我没有找到任何日志。
private RestApiStack() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
// preview requests
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(interceptor);
}
OkHttpClient client = builder.build();
Retrofit retrofit = (new Retrofit.Builder())
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(/*...*/)
.build();
api = retrofit.create(ApiStack.class);
}
implementation "com.squareup.okhttp3:logging-interceptor:3.9.1"
implementation "com.squareup.okhttp3:okhttp:3.11.0"