【发布时间】:2014-03-21 04:01:11
【问题描述】:
如何调试/检查 apk webview 的元素。
我试过this,但它只对chrome有用,对apk没有帮助。
请给我建议
【问题讨论】:
标签: android debugging android-webview inspect
如何调试/检查 apk webview 的元素。
我试过this,但它只对chrome有用,对apk没有帮助。
请给我建议
【问题讨论】:
标签: android debugging android-webview inspect
试试这个:
在设备中启用开发者选项(设置-->关于手机-->在版本号上点击 7 次)
打开开发者选项并启用 USB 调试(在开发者选项中)
将此行添加到您的自定义应用程序类或加载 Web 视图的 Activity 中
// 如果您的构建处于调试模式,则启用 Web 视图检查
if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE)) {
WebView.setWebContentsDebuggingEnabled(true);
}
打开 Chrome 并输入 chrome://inspect/#devices,您应该会在远程目标列表中看到您的设备
点击检查进行调试。
更新: 您可以将其简化如下:
WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG)
【讨论】:
这对我有用,覆盖 MainActivity.java 中的方法 onCreate 并在方法 WebView.setWebContentsDebuggingEnabled(true) 中添加这一行。
我的代码如下所示:
package com.myapp;
import com.facebook.react.ReactActivity;
import android.webkit.WebView;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript.
* This is used to schedule rendering of the component.
*/
@Override
protected String getMainComponentName() {
return "myapp";
}
@Override
protected void onCreate() {
super.onCreate();
//added this line with necessary imports at the top.
WebView.setWebContentsDebuggingEnabled(true);
}
}
构建您的代码,在手机中打开您的应用程序并转到 chrome://inspect ,您会在此处看到您的应用程序。点击检查链接。
【讨论】:
v0.57.3 上仅供参考,无需导入 android.os.Bundle,因为 onCreate() 方法不再需要它
no suitable method found for onCreate(no arguments)
如果您正在寻找一种方法来为您不拥有源代码的应用打开 WebView 调试,则可以这样做,但您需要反编译并重新编译应用程序。
他可以在此处找到有关如何执行此操作的说明:https://blog.speedfox.co.uk/articles/1524219174-Android_WebView_Hackery
【讨论】:
我看到有一个关于 webView 的章节。你尝试了吗? https://developers.google.com/chrome-developer-tools/docs/remote-debugging#debugging-webviews
似乎需要:
运行 Android 4.4 或更高版本的 Android 设备或模拟器,已启用 USB 调试,如 2. 在您的设备上启用 USB 调试中所述。
Chrome 30 或更高版本。
【讨论】:
在 react-native-webview 中,他们给出了 IOS 和 Android 的解释。
https://github.com/react-native-community/react-native-webview/blob/master/docs/Debugging.md
帮我做IOS。
【讨论】:
要在 android 应用程序中调试 webviews,您必须在 WebviewActivity 中设置 WebView.setWebContentsDebuggingEnabled(true)
打开 chrome://inspect/#device 进行调试。使用端口转发。 https://developers.google.com/web/tools/chrome-devtools/remote-debugging/webviews
【讨论】: