Using jdb (java debugger) with adb (android debug bridge) to debug Android app on a handset (without ADT plugin).

Method 1: Debug from CLI

Launch target apk.  Get pid of target app. Forward target app remote port (jdwp:<pid>) to local tcp port (tcp:<#>).  Attach jdp to specified tcp port.

(apk manifest with debuggable=”true”)

scripts:

#!/bin/bash
#adb kill-server
#sleep 1
#adb start-server
adb wait-for-device
cmd="adb -d shell am start -e debug true -a android.intent.action.MAIN -c android.intent.category.LAUNCHER -n com.thirdwhale/com.thirdwhale.activity.SplashActivity";
echo $cmd;
exec $cmd &
app_debug_port=$(adb jdwp | tail -1);
echo "app_debug_port: $app_debug_port";
cmd0="adb -d forward tcp:29882 jdwp:$app_debug_port";
echo $cmd0;
exec $cmd0 &
cmd1="jdb -J-Duser.home=. -connect com.sun.jdi.SocketAttach:hostname=localhost,port=29882  -sourcepath C:/workspaces/android/3rdWhale_import2/src/main/java";
cmd2="jdb -J-Duser.home=. -attach asantoso_xpl:29882";
echo $cmd1;
exec $cmd1;

sample jdb.ini:

stop in com.thirdwhale.activity.SplashActivity.onResume()
stop in com.thirdwhale.activity.NewsActivity.onResume()
stop in com.thirdwhale.activity.WhatsAround.onResume()

notes:

try killing standalone ddms and eclipse adt ddms

Method 2: Using debug feature in Eclipse (without ADT)

1. Open Debug dialog
2. Create a “Remote Java Application” configuration
3. Set source path
4. Connection type: Socket attach
5. Set host to localhost
6. Set port to your specified forward port (example: 29882)
7. Save debug configuration.
8. Create breakpoints.
9. Compile project and install apk to device.
10 Open Eclipse debug perspective.
11 Go to the device shell, and start activity using ActivityManager(am) with “-e debug true” parameter. (use above script but comment out the jdb)
12 start your debug configuration in Eclipse. (Eclipse will establish a connection to the port specified 29982)

About these ads

About this entry