2014-04-19 22 views
13

Trong bộ công cụ android, triển khai URLConnection đã được thay thế bằng OkHttp, Làm cách nào để gỡ lỗi?Cách gỡ lỗi "com.android.okhttp"

Các OkHttp là trong thư mục này: external/okhttp/android/main/java/com/squareup/okhttp

Khi tôi gọi UrlInstance.openConnection().getClass().getName(), nó hiện com.android.okhttp.internal.http.HttpURLConnectionImpl

Làm thế nào tôi có thể gỡ lỗi nó? Dường như tôi không thể kết hợp /android/main/java/com/squareup/okhttp/* đến com.android.okhttp.*

Khi mã thực thi vào 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); 
} 

Go tiến xa hơn, nhưng không thể thâm nhập vào các com.squareup.okhttp.HttpHandler#openConnection

The nhấn mạnh thread trong trình gỡ rối trong hình bên dưới có màu xám.

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; 
    } 
} 

enter image description here

+0

Bạn muốn làm gì chính xác? – eleven

+0

@Foxinsocks OkHttp nằm trong các nguồn của AOSP bên ngoài/okhttp/android/main/java/com/squareup/okhttp', nhưng, lớp thời gian chạy là 'com.android.okhttp.internal.http.HttpURLConnectionImpl'. Tôi muốn làm theo các bước mã từng bước, nhưng bây giờ, tôi không thể – log1000

+0

@ Foxinsocks tôi muốn thực hiện theo việc thực thi mã. Nhưng, tôi không biết làm thế nào để assoiate các nguồn OkHttp để 'com.android.okhttp' – log1000

Trả lời

2

Có vẻ như từ phiên bản 0.8.x trở đi của Android Studio tùy chọn để đính kèm nguồn cụ thể tại Android SDK đã được gỡ bỏ (Đọc ý kiến ​​ở đây https://plus.google.com/+CyrilMottier/posts/GNcGL6xVth1).

Tôi đoán nếu bạn muốn gỡ lỗi, bạn có thể thử phiên bản cũ hơn hoặc Android Studio hoặc (và tôi muốn giải pháp này) xuất một phần ứng dụng của bạn sang Eclipse (phiên bản SDK Android), có thể chỉ là một phần liên quan đến kết nối phiền hà, và ở đó bạn có thể đính kèm nguồn cho một lớp không có nguồn đính kèm trong quá trình gỡ lỗi rất dễ dàng, bạn sẽ thấy một trang chỉ có chữ ký của các phương thức trong Chế độ xem mã nguồn, với nút "Đính kèm nguồn "

http://4.bp.blogspot.com/-a2EnbC4wP6g/UN2Z7QzFlyI/AAAAAAAAAg0/D2tFh6AgRrM/s1600/Eclipse_String_Class_File.PNG

Các vấn đề liên quan