title: debugging android app with "jdb -attach" (or jswat)
body: <p>I'm having troubles with using a stand-alone java debugger with android apps on emulator.  Apparently, any remote-capable java debugger such as jdb (or jswat) could be leveraged, by following the steps below (as I understand after reading here and there):</p>
  
  <p>1) turn on the emulator, install your app on the emulator (adb install)</p>
  
  <p>2) turn on the dalvik server (ddms)</p>
  
  <p>3) on the emulator, run the "DevTools" app --> "Development Settings" --> select the app you want to debug, enable the  "Wait for debugger" flag</p>
  
  <p>4) again in the emulator, run your app; it will block, waiting for a debugger to attach, and dalvik will show a new process flagged by a "red bug"</p>
  
  <p>5) on dalvik, select the red-flagged process; its debug port is thus forwarded to localhost:8700</p>
  
  <p>6) hook the debugger to localhost:8700.  With jdb you have to run "jdb -attach 8700"</p>
  
  <p>As soon as the debugger is launched, your app on the emulator unblocks.  So, it seems that the app has properly detected a debugger and thus runs free.</p>
  
  <p>The point, however, is that it "runs free", that is, it will not wait for the debugger to issue a "run" command.  So I have no chance to set up any breakpoints.</p>
  
  <p>Following hints from <a href="https://stackoverflow.com/questions/3107587/android-with-jdb-confusion-using-waitfordebugger/3908538">1</a>,I've tried putting waiting loops at the beginning of my app, in the hope I'd have the time to set a breakpoint.  When I try to set a breakpoint, jdb says "Deferring breakpoint XXX.YYY. It will be set after the class is loaded.", as the app was not running yet.  But, if I then issue a "run" command, the answer is "Nothing suspended.", as the app was already running (and it is indeed).</p>
  
  <p>With jswat you don't see al these messages but the final result is the same :-(</p>
  
  <p>Needless to say, "jdb -attach" works just fine with non-android java apps running on localhost.</p>
  
  <p>Any hints (except "please use eclipse")?</p>
  
  <p>Am I just missing a stupid detail anywhere?</p>
  
  <p>The app is a HelloWorld, build command is "ant debug".</p>
  
  <p>Thank you in advance.</p>