Chrome Inspect Device not showing android app

2019-06-07 05:09发布

问题:

I am trying to debug this app using chrome://inspect - Devices, but I am not able to see my app in the debug app list. I can see the device name and only Chrome app under it, but not my app.

Settings that I have applied

  • Enable USB Debugging (Android Device)
  • Discover USD Devices (Chrome Dev Tools)
  • Select Debug app - App Name
  • Use USB for - File Transfer
  • Added android:debuggable="true" in Manifest file

I have also tried using different USB cables, different android device, but no luck.

回答1:

Found answer on Remote Debugging WebViews on Google Developers.

This method has been added in API Level 19, hence had to add following check

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  WebView.setWebContentsDebuggingEnabled(true);
}

As mentioned in documentation, this method does not respect debuggable flag in application manifest file. If you want to enable webview debugging only when debuggable flag is true, then add one more check

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
  if (0 != (getApplicationInfo().flags & ApplicationInfo.FLAG_DEBUGGABLE))
  { 
    WebView.setWebContentsDebuggingEnabled(true); 
  }
}