I have a webview that works fine on iOS, but not Android. Is there a tool where I can connect to Android webview in browser and debug it using firefox or webkit console?
Currently I have no idea what is causing the webview not to work in Android.
In iOS I am able to open my iPad or iPhone simulator, open the webview pane, and in my desktop browser I listen to port 9999, and it shows me the tools you see in webkit developer tool/debugging tools.
I am looking for similar tool for Android, or at least to get me started on debugging.
Check out weinre. It provides Chrome developer-like tools for debugging from WebKit browsers to browsers running on remote devices.
The easiest way to debug WebView is to connect your Android device to PC by USB and inspect your WebView by Chrome dev tools.
So, you will need:
1) Activate USB debugging on our devise. You can find it
Settings >> Developer Options >> Debugging >> USB Debugging (activate checkbox)
2) Connect you devise to Computer by USB
Note: If you are developing on Windows, install the appropriate USB driver for your device. See OEM USB Drivers on the Android Developers’ site.
3) Open Chrome browser and type in the URL field:
4) Confirm that ‘Discover USB devices’ activated
5) On your device, an alert prompts you to allow USB debugging from your computer. Tap OK.
6) On the chrome://inspect page displays every connected device. Click
inspect for connected device and you will get console.
More detailed manual is Debugging Android WebView
If you are not using Android 4.4, according to http://developer.android.com/guide/webapps/debugging.html you’re going to enjoy the old-school way of debugging …
If you don’t have a device running Android 4.4 or higher, you can
output messages to logcat.
For Android 4.4 and better, you’ll enjoy remote debugging, see https://developers.google.com/chrome-developer-tools/docs/remote-debugging#debugging-webviews
Starting Android 4.4 (KitKat), you can use the DevTools to debug the
contents of Android WebViews inside native Android applications.
Those are the steps i use to debug a
WebView content in a device:
- Enabled Developer Mode in your device
- Plug the device in the PC and enable USB debugging (install driver if needed)
Add this line in your custom
Applicationclass or in the
Activitywhere the webview is loaded
//if your build is in debug mode, enable webviews inspection WebView.setWebContentsDebuggingEnabled(BuildConfig.DEBUG);
Open Chrome and go to
chrome://inspectand you should see your device in the Remote Target list
- Start debugging of your app from Android Studio
- When a
WebViewwill be added to the layout, in the tab you opened will appear a screenshot with a Inspect button, click there and a Chrome developer console will open
When your java methods aren’t called, it generally means you have made some sort of error in your JS code.
I know this is no high tech solution to your issue, but it is something at least, and it worked for me.
Try to acces to ADB Logcat of the device by installing adb on your desktop…