如何调试" com.android.okhttp" [英] How to debug "com.android.okhttp"
问题描述
在Android的奇巧,URLConnection的的实现已取代OkHttp,它如何调试呢?
In android kitkat, URLConnection's implementation has been replaced by OkHttp,How can it debug it?
该OkHttp此目录中:外部/ okhttp /安卓/主/ JAVA / COM / squareup / okhttp
The OkHttp is in this directory:external/okhttp/android/main/java/com/squareup/okhttp
当我称之为 UrlInstance.openConnection()。的getClass()。的getName()
,它present com.android.okhttp .internal.http.HttpURLConnectionImpl
When i call the UrlInstance.openConnection().getClass().getName()
, it present com.android.okhttp.internal.http.HttpURLConnectionImpl
我怎么能调试吗?看来,我不能在 /安卓/主/ JAVA / COM / squareup / okhttp / *
到 com.android.okhttp关联。 *
How can i debug the it ? It seems that i can't associate the /android/main/java/com/squareup/okhttp/*
to the com.android.okhttp.*
当code EXCUTE到返回streamHandler.openConnection(本);
When the code excute to the return streamHandler.openConnection(this);
/**
* Returns a new connection to the resource referred to by this URL.
*
* @throws IOException if an error occurs while opening the connection.
*/
public URLConnection openConnection() throws IOException {
return streamHandler.openConnection(this);
}
往前走进一步,但不能深入到 com.squareup.okhttp.HttpHandler#的openConnection
表示在下面的图片突出了调试器线程是灰色的。
The The highlighted thread in debugger in the picture below is gray.
package com.squareup.okhttp;
import java.io.IOException;
import java.net.Proxy;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
public class HttpHandler extends URLStreamHandler {
@Override protected URLConnection openConnection(URL url) throws IOException {
return newOkHttpClient(null /* proxy */).open(url);
}
@Override protected URLConnection openConnection(URL url, Proxy proxy) throws IOException {
if (url == null || proxy == null) {
throw new IllegalArgumentException("url == null || proxy == null");
}
return newOkHttpClient(proxy).open(url);
}
@Override protected int getDefaultPort() {
return 80;
}
protected OkHttpClient newOkHttpClient(Proxy proxy) {
OkHttpClient client = new OkHttpClient();
client.setFollowProtocolRedirects(false);
if (proxy != null) {
client.setProxy(proxy);
}
return client;
}
}
推荐答案
这从版本0.8.4起Android的工作室已被删除(阅读评论这里的 https://plus.google.com/+CyrilMottier/posts/GNcGL6xVth1 )。
It seems from version 0.8.x onwards of Android Studio the option to attach specific sources at the Android SDK has been removed (Read comments here https://plus.google.com/+CyrilMottier/posts/GNcGL6xVth1).
我想,如果你想调试你可以尝试的是旧版本或Android工作室,或(和我会用这个解决方案去)导出应用程序到Eclipse(Android的SDK版本)的一部分,也许只是部分涉及麻烦的连接,在那里你可以附加来源有没有很方便地调试中连接源的一类,你会看到一个页面的源$ C $ C查看方法只是签名的按钮附加源
I guess if you want to debug you could try an older version or Android Studio, or (and I'd go with this solution) export a portion of your application to Eclipse (the Android SDK version), maybe just the part involving the troublesome connection, and there you can attach sources for a class that has no sources attached during debug very easily, you should see a page with just the signatures of the methods in the Source Code View, with the button to "Attach source"
这篇关于如何调试" com.android.okhttp"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!