Ho-ho-ho, it works now! Here is a (more or less detailed) instruction to debug a Smali code of a third-part Android application. To debug Smali code with apk-tool, you need
Apk-tool 1.4.1 and NetBeans 6.8. Use these versions, not the latest ones! Currently, the latest versions of apk-tool and NetBeans do not allow to debug Smali code.
Java, JDK and other stuff installed in your system to make Apk-tool and NetBeans working
The step-by-step instruction:
Decode your .apk file to
out directory, use
-d option:`java -jar apktool.jar d -d my.app.apk out
android:debuggable="true" attribute to
<application> section in
out directory to .apk file:
$ java -jar apktool.jar b -d out my.app.to.debug.apk
Sing and install
my.app.to.debug.apk to the Android device used for debugging
out/build folderRun NetBeans, click “File” –> “New Project”. Choose “Java” –> “Java Project with Existing Sources”. Click “Next”.
out as “Project Folder”. Click “Next”.
out/smali folder to the “Source Package Folder” list. Click “Next” and then “Finish”.
my.app.to.debug.apk on the device, run DDMS, find your application on a list and click it. Note port information in last column - it should be something like
86xx / 8700.
In NetBeans, click “Debug” –> “Attach Debugger” –> select “JPDA” and set “Port” to
8700 (or whatever you saw in previous step). Rest of fields should be ok, click “OK”.
Debugging session should start: you will see some info in a log and debugging buttons will show up in top panel.
Set a breakpoint. You must select line with some instruction, you can’t set breakpoint on lines starting with
Trigger some action in application. If you run at breakpoint, then thread should stop and you will be able to debug step by step, watch variables, etc.
I copy-pasted steps 9-13 from the original instruction (sorry, English is not my native language… and I’m too lazy to “produce unique content for the blog”™, so just copy-pasted description of last 5 steps :)).
Questions are welcome. Have a nice day :)
P.S. If you have problems with breakpoints, this may help.
Commenting is not available in this blog, but you can write me a letter or message. Please, note that English is not my native language. I'm sorry for mistakes/missprints, if any.Next: Breakpoints in Smali code