title: How to debug an android application started from 'adb shell am start -D '?
body: <p>I need to debug an android application that is already installed on a phone. I am able to start the application in debug mode but I <strong>can't connect</strong> to the process using JDWP. I have try two different ways that both fail. (see following sections)</p>
  
  <hr>
  
  <p><strong>Command line attempt</strong></p>
  
  <p>1- Start the application </p>
  
  <pre><code>[...]sdk\platform-tools&gt;adb -d shell am start -D -n "package/package.SomeActivity"
  </code></pre>
  
  <p>The application starts and a alert display "/!\ Waiting for debugger".</p>
  
  <p>2- Open a JDWP port</p>
  
  <pre><code>[...]sdk\platform-tools&gt;adb forward tcp:8000 jdwp:7602
  </code></pre>
  
  <p>3- Attempt to connect using jdb</p>
  
  <pre><code>[...]sdk\platform-tools&gt;jdb -attach 127.0.0.1:8000
      java.io.IOException: shmemBase_attach failed:
          at com.sun.tools.jdi.SharedMemoryTransportService.attach0(Native Method)
          at com.sun.tools.jdi.SharedMemoryTransportService.attach(SharedMemoryTransportService.java:108)
          at com.sun.tools.jdi.GenericAttachingConnector.attach(GenericAttachingConnector.java:116)
          at com.sun.tools.jdi.SharedMemoryAttachingConnector.attach(SharedMemoryAttachingConnector.java:63)
          at com.sun.tools.example.debug.tty.VMConnection.attachTarget(VMConnection.java:519)
          at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:328)
          at com.sun.tools.example.debug.tty.Env.init(Env.java:63)
          at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1066)
  Fatal error:
  Unable to attach to target VM.
  </code></pre>
  
  <hr>
  
  <p><strong>IntelliJ attempt</strong></p>
  
  <p>I have configure my local project to start the default Activity and uncheck the "Deploy application".</p>
  
  <p>I also get the application started with the same alert but unfortunately the IDE doesn't connect to the remote process.</p>
  
  <pre><code>Target device: 42f7cc14e2acbfab
  Launching application: ********/********.SomeActivity.
  DEVICE SHELL COMMAND: am start -D -n "********/********.SomeActivity"
  Starting: Intent { cmp=********/********.SomeActivity }
  
  Waiting for process: ********
  </code></pre>