debug javascript in android emulator with phonegap
I am new to phonegap and android development. May I know how can I debug javascript error on the emulator? I have heard about ADB may I know how can I use and install it on windows 7 system? I have an ajax called with jsonp but no response on emulator. However, I can call that ajax with browser on windows. May I know what went wrong?
Update Nov 2016: looks like this doesn't work anymore.
The easiest and one of the most powerful ways is using http://debug.phonegap.com (it uses Weinre in the background, if you care). You just
- pick a random string, say
r4nd0m
, - inject
<script src="http://debug.phonegap.com/target/target-script-min.js#r4nd0m"></script>
into yourindex.html
- visit
http://debug.phonegap.com/client/#r4nd0m
and you will instantly be debugging your mobile web app.
Things you can do (similar to Firebug or Web Inspector):
- Viewing and changing the DOM
- Editing CSS
- Console for live debugging and running Javascript remotely.
- Other stuff, like: storage, resources, timeline, profile, etc.
You could at least log debug stuff to the adb console by calling console.log() in JavaScript. Maybe that would suffice?
To view log output using adb, navigate to your SDK platform-tools/ directory and execute:
adb logcat
See logcat Command-line Tool
You can now use Chrome dev tools to remotely debug Android Phonegap apps! I wrote up instructions here: Remote debugging Phonegap apps with Chrome Dev Tools
Steps for Android emulator:
- Navigate to chrome://inspect/ in Google Chrome on your desktop computer.
- Locate Android emulator on Devices tab and click 'inspect' link
See also Get Started with Remote Debugging Android Devices
I'd recommend jsconsole. It lets you inject any JavaScript into the page and provides a basic console. There's a nice tutorial on remote debugging.
Yes, you have log errors with console.log and show the LogCat tab in Eclipse. There, Web Console messages (including JS errors) will show up. It's a little verbose so you have to filter to show just the Web Console tags but it works well. Described here: SHOWING CONSOLE CONSOLE.LOG OUTPUT AND JAVASCRIPT ERRORS WITH PHONEGAP ON ANDROID/ECLIPSE