1

In an Android WebView, it is now pretty easy to allow debugging in Chrome on an attached computer. Just add this code and you can debug a WebView just like a page you have open in Chrome:

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

Works great. Wonderful. I'm using it in a Cordova app I'm working on.

My question is, can this cause any problems? Is there any reason I shouldn't leave debugging enabled if I release my app publicly? I presume there must be, otherwise it would just be enabled by default and any WebView would be debuggable. But I don't know why.

dumbmatter
  • 9,351
  • 7
  • 41
  • 80

1 Answers1

3

It's OK to leave the WebView debugging mode on while your testing and debugging but not when it's live. It would raise a number of risks and open your app to tampering by end users.

You should just extend your Kitkat version condition to include the debug mode from the Manifest file. This stackoverflow answer outlines how to get the debug mode.

It would look something like this:

boolean isDebuggable = (0 != ( getApplicationInfo().flags &= ApplicationInfo.FLAG_DEBUGGABLE));

if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && isDebuggable) {
    WebView.setWebContentsDebuggingEnabled(true);
}
Community
  • 1
  • 1
Steven Trigg
  • 1,903
  • 2
  • 19
  • 22
  • Thanks! Since I'm a complete newb, I can't get that to compile. Am I supposed to be importing anything extra? – dumbmatter Jun 06 '14 at 02:00
  • Make sure you have the flag in your Manifest file. http://stackoverflow.com/questions/2409923/what-do-i-have-to-add-to-the-manifest-to-debug-an-android-application-on-an-actu I'm not sure what else. Let me know if you have any more issues. Cheers. – Steven Trigg Jun 06 '14 at 02:26
  • Doesn't change anything. I have no problem debugging my WebView, it's just that when I add the isDebuggable line it doesn't compile. I'm running `cordova run android` and it fails with these three lines and basically no other info: `BUILD FAILED`, `adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:720: The following error occurred while executing this line:`, `adt-bundle-linux-x86_64-20131030/sdk/tools/ant/build.xml:734: Compile failed; see the compiler error output for details.` (I accepted your answer because this is a different problem than my original question, but I'm still stuck!) – dumbmatter Jun 06 '14 at 02:34
  • I don't know any Java, but do I need to be importing `getApplicationInfo` and `ApplicationInfo` from somewhere? Otherwise, what are they? Google wasn't helpful. – dumbmatter Jun 06 '14 at 02:35