Android Studio 2022.2.1:网络检查器数据不可用

Int*_*ive 5 android-studio

我正在使用最新最好的 Android Studio 版本:

Android Studio Flamingo | 2022.2.1
Build #AI-222.4459.24.2221.9862592, built on March 31, 2023
Runtime version: 17.0.6+0-b2043.56-9586694 amd64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
Windows 10 10.0
Run Code Online (Sandbox Code Playgroud)

到目前为止,它工作得很好,但是当我尝试检查https://developer.android.com/studio/debug/network-profiler中所述的流量详细信息时,我在窗口中看到一个 Connection View选项卡Network Inspector

网络检查器数据不可用

我可能在配置和操作方式中遗漏了一些琐碎的事情:我需要做什么才能查看正式文档Connection View中所示的填充行?

正确填充连接视图行

注意:正式文件指出

“目前,网络检查器仅支持 HttpsURLConnectionOkHttp网络连接库。如果您的应用程序使用其他网络连接库,您可能无法在网络检查器中查看网络活动。”

如何判断WebView.loadUrl()是否使用HttpsURLConnectionand/or OkHttp


更新:纯粹是偶然,由于我的代码中使用HttpURLConnection 的另一部分,我成功地在网络检查器上“捕获了一个斑点” :

HttpURLConnection httpConnection = null;
try {
    URL testurl = new URL("https://www.google.com");
    URLConnection connection = testurl.openConnection();
    connection.setConnectTimeout(5 * 1000);

    httpConnection = (HttpURLConnection) connection;
    int responseCode = httpConnection.getResponseCode();
    ...
}
Run Code Online (Sandbox Code Playgroud)

连接视图显示该请求以及关联的数据(根据需要):

HttpURLConnection 连接视图

所以,我现在的两个问题是:

  1. 如何判断WebView.loadUrl()是否使用HttpsURLConnectionand/or OkHttp
  2. 我需要做什么才能查看WebView.loadUrl()Connection View的填充行?

G. *_*nam 2

这个较旧的答案似乎是迄今为止我发现的最好的答案,Webview“使用 Chrome 网络堆栈的快照,或者对于 HC 之前的设备使用 WebKit 网络堆栈”。来自 marcin.kosiba 的回答。

这个答案提供了一种强制使用 OkHttp 作为实际网络堆栈和shouldInterceptRequest. 请参阅 Michalsx 的回答。

这篇文章来看,关于Webview的问题也并不容易,因为Webview不断被Google改变。

“早期版本的 WebView 被集成为核心操作系统的一部分。随着 Android 5.0 的发布,Google 将 WebView 从核心操作系统中分离出来。Google 在 7.0、8.0 和 9.0 版本中将 WebView 与 Google Chrome 结合在一起。而到了 Android 10.0,它又回归了。将其作为一个单独的组件。”

来自开发人员 - 管理 WebView 对象“从 Android 7.0(API 级别 24)开始,用户可以在几个不同的包中进行选择,以在 WebView 对象中显示 Web 内容...使用特定包的 WebView 实现来显示 Web 内容。”