title: Remotely debugging android NDK app using VSCode
body: <p>I've tried a number of ways to get this to work but to no avail so far.
  My requirements are as follows:</p>
  <ul>
  <li>To be able to connect using visual studio code &amp; gdb to a debug-enabled APK process running on an android device</li>
  <li>The device should not have to be rooted</li>
  <li>I expect full visual debugging of C++ NDK code on that device. Java code would be nice too but C++ is what I'm interested in.</li>
  </ul>
  <p>I'm aware that the gdb server must run on the device. A python script in the NDK (ndk-gdb) can copy this to the device and execute it, which then launches its own shell which can be used to set breakpoints, which is useful in a pinch but nowhere near as intuitive as a full GUI.</p>
  <p>So, given that the gdb-server is now running on the device, I should be able to connect to it.</p>
  <p>I'm trying to use this 'launch.json' debug config in vs-code:</p>
  <pre><code>{
      &quot;name&quot;: &quot;Debug App on Device&quot;,
      &quot;type&quot;: &quot;cppdbg&quot;,
      &quot;request&quot;: &quot;launch&quot;,            
      &quot;cwd&quot;: &quot;${workspaceRoot}&quot;,
      &quot;program&quot;:&quot;${workspaceRoot}\\android-build\\DebugSys\\system\\bin\\app_process64&quot;,
              &quot;additionalSOLibSearchPath&quot;: &quot;${workspaceRoot}\\android-build\\obj\\local\\arm64-v8a&quot;,
      &quot;miDebuggerServerAddress&quot;: &quot;192.168.1.121:5039&quot;,
      &quot;setupCommands&quot;: [{
          &quot;text&quot;: &quot;set solib-absolute-prefix ${workspaceRoot}/android-build/&quot;,
          &quot;ignoreFailures&quot;: false
      }],
      &quot;windows&quot;: {
           &quot;miDebuggerPath&quot;: &quot;C:\\Users\\luthe\\AppData\\Local\\Android\\Sdk\\ndk\\23.1.7779620\\prebuilt\\windows-x86_64\\bin\\gdb.exe&quot;,
           &quot;MIMode&quot;: &quot;gdb&quot;
           }
  },
  </code></pre>
  <p>But running it gives me this error:</p>
  <p><a href="https://i.stack.imgur.com/vam7E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vam7E.png" alt="enter image description here" /></a></p>
  <p>(No connection could be made because the target machine actively refused it).</p>
  <p>This probably isn't a firewall issue as I'm able to connect to another server I have running, launched by the app in question on port 8080.</p>
  <p>Is there an error in my 'launch.json' or am I going about all of this in entirely the wrong way.
  Also, would it make sense for my app to launch the gdb server instead or is it better/neutral to have ndk-gdb do it?</p>