Enable webview debug on release/production build

Is it possible to enable the webview debug on a production build?

Some background, we use the Playstore Alpha/Beta channels for testing new versions with specific users. This gives us much more/quicker feedback. But sometimes a stacktrace from the Developer Console would be helpful.
So in short, we want to be able to build a signed apk for uploading to the Alpha/Beta channel, which still has the webview debug enabled.

In Cordova land this is debug vs. release.

Isn’t the difference between those two exactly that the debug options are not enabled?
Can you upload native apps with debugging enabled to those channels?

Hi Sujan,

Thanks for the reply, I understand the difference, and for typical usage it is fine. This is what we use for the actual release deployment, and works as expected.

And no, I do not know of a way to upload a debug apk to the channel. This is blocked by Google, which I do understand as well. But IMO this conflicts with the idea of test channels…

I was hoping I could build a release APK with the webview debug still enabled.

I am not 100% sure how cordova-android achieves the enabling or disabling of debugging functionality for the webview - you would probably have to jump into its code to check.

They have a different definition of testing. Technical testing like you want, is normally done via HockeyApp etc (with all its disadvantages of a separate system etc).

We already use TestFairy, and for most testing this works fairly well, but we are now using In-App-Purchases as well. With an active app in the Store Console, this works with updates via TestFairy as well. But I was hoping to be able to move to one system due to other disadvantages (as you mentioned).

I guess we will have to stick to TestFairy for now with a select group of dedicated testers. Thanks for the quick replies!

(Please do investigate further, maybe there is actually a way to sneak the webview debug functionality in while changing all the other stuff - I am note sure how this works and would have to jump into the code myself as well)

I did some more digging/searching, and the webview has a method to enable remote debugging. See code snippet below.

If I always enable remote debugging I can inspect the app in Chrome, even when built using --release. At this moment I do not have access to the Play Store console, so I can’t try if it now is accepted by the store or not. I will get back to that one later this week hopefully.
But so far it is looking good. Since it is simple to enable remote debugging, it can easily be made into a small plugin.

In {project}/platforms/android/CordovaLib/src/org/apache/cordova/engine/SystemWebViewEngine.java

    //Determine whether we're in debug or release mode, and turn on Debugging!
    ApplicationInfo appInfo = webView.getContext().getApplicationContext().getApplicationInfo();
    if ((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0 &&
        android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
        enableRemoteDebugging();
    }

  ....

    @TargetApi(Build.VERSION_CODES.KITKAT)
    private void enableRemoteDebugging() {
        try {
            WebView.setWebContentsDebuggingEnabled(true);
        } catch (IllegalArgumentException e) {
            LOG.d(TAG, "You have one job! To turn on Remote Web Debugging! YOU HAVE FAILED! ");
            e.printStackTrace();
        }
    }
2 Likes

We’ve had a chance to test this on the Play Store, and it works as expected! The app now shows on the Inspect list of Chrome.

For anyone who is interested in it, we’ve created a plugin for this. The config.xml can be used to enable/disable debugging of the webview.

Kinda related, currently we use some regexp to replace the value in the config during (debug/release) build. Is there some easier/cleaner way to pass variables to the build so that the config.xml is updated?

4 Likes