Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ffabreti/8fd551ed321d51d7f458 to your computer and use it in GitHub Desktop.
Save ffabreti/8fd551ed321d51d7f458 to your computer and use it in GitHub Desktop.
Debugging Titanium Android applications with node-inspector
Thanks to Stevo Perisic
Download the https://github.com/node-inspector/node-inspector using
$ npm install -g node-inspector
Than go to your titanium project folder and run:
$ node-inspector
after that in the same dir run:
JAVA_HOME=/usr/java/latest titanium build -f -p android -T emulator -I 7 -S HVGA --debug-host localhost:5858
in your browser open localhost:8080/debug?port=5858
and voila! You have the chrome inspector in your android titanium project!
notice:
titanium build "-I 7 -S HVGA" option tries to spawn avd named titanium_7_HVGA
@gazialankus
Copy link

By the way, this also seems to work with GenyMotion. Here's the end of my command line: --device-id 192.168.56.103:5555 --debug-host adb:5858

Here's what I did to get this: I ensured Log Level is at least Info in Titanium Studio and pressed Debug in my GenyMotion setup. Right then it spits out the command that it uses to run the project (you can hide the dialog that shows the status to access the console). It was line 22 in the console, in my case. The command is something like this:

node c:\path\to\titanium --no-colors ... --device-id 192.168.56.103:5555 --debug-host adb:9149

Copy this line somewhere, add --skip-js-minify to it and change the port in the very end to the port that you'll use (adb:5858). Run it in a cmd with the appropriate JAVA_HOME and PATH variables set.

Then, you can connect to it just as above. It initially breaks at Titanium's module loading code. Once it loads your app.js, you can find it in the list of sources and add breakpoints to your own code.

However, the extra benefit of this seems to be just the interactive console with autocomplete. The rest is covered by Titanium's debugger just fine. The console can be a huge benefit sometimes, but I wish it would be simpler to reach it.

@gazialankus
Copy link

Actually I just found a much easier way to do this all.

  1. Disable JavaScript minification in the Debug Configuration in Titanium Studio.
  2. Press debug in Titanium Studio.
  3. Once you see the application running in GenyMotion, look at the Titanium Studio console to find the command it was ran with (in the console, see above comment), and from there copy the debug port number (the number in adb:11421 at the very end of the command).
  4. Stop the Titanium Studio debugger with the red stop button.
  5. Visit http://127.0.0.1:8080/debug?port=11421 (with the port number that you copied)
  6. Enjoy!

It seems to remember breakpoints across runs, too. The only caveat is that you lose the ability to log with Ti.API.info() and such. But since you are debugging line by line, you won't really need that much. You could probably set Ti.API.info function to a function of your choice from the node-inspector console if you really needed that anyway.

@ffabreti
Copy link
Author

Great. Thanks, will give it a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment