Display and control your Android device
Add debugging method for Android >= 11
Enno Bolanddc82425769ab
diff --git a/app/src/server.c b/app/src/server.cindex 9101aee9..584a3c34 100644--- a/app/src/server.c+++ b/app/src/server.c@@ -213,10 +213,15 @@ execute_server(struct sc_server *server,// Android < 9dbg = "-agentlib:jdwp=transport=dt_socket,suspend=y,server=y,address="SERVER_DEBUGGER_PORT;- } else {- // Android >= 9+ } else if (sdk_version < 30) {+ // Android >= 9 && Android < 11dbg = "-XjdwpProvider:internal -XjdwpOptions:transport=dt_socket,""suspend=y,server=y,address=" SERVER_DEBUGGER_PORT;+ } else {+ // Android >= 11+ // Contrary to the other methods, this does not suspend on start.+ // <https://github.com/Genymobile/scrcpy/pull/5466>+ dbg = "-XjdwpProvider:adbconnection";}cmd[count++] = dbg;#endif@@ -408,10 +413,14 @@ execute_server(struct sc_server *server,cmd[count++] = NULL;#ifdef SERVER_DEBUGGER- LOGI("Server debugger waiting for a client on device port "- SERVER_DEBUGGER_PORT "...");- // From the computer, run- // adb forward tcp:5005 tcp:5005+ LOGI("Server debugger listening%s...",+ sdk_version < 30 ? " on port " SERVER_DEBUGGER_PORT : "");+ // For Android < 11, from the computer:+ // - run `adb forward tcp:5005 tcp:5005`+ // For Android >= 11:+ // - execute `adb jdwp` to get the jdwp port+ // - run `adb forward tcp:5005 jdwp:XXXX` (replace XXXX)+ //// Then, from Android Studio: Run > Debug > Edit configurations...// On the left, click on '+', "Remote", with:// Host: localhostdiff --git a/doc/develop.md b/doc/develop.mdindex fb75f471..21949ea6 100644--- a/doc/develop.md+++ b/doc/develop.md@@ -461,17 +461,30 @@ meson setup x -Dserver_debugger=truemeson configure x -Dserver_debugger=true```-Then recompile.+Then recompile, and run scrcpy.-When you start scrcpy, it will start a debugger on port 5005 on the device.+For Android < 11, it will start a debugger on port 5005 on the device and wait:Redirect that port to the computer:```bashadb forward tcp:5005 tcp:5005```-In Android Studio, _Run_ > _Debug_ > _Edit configurations..._ On the left, click on-`+`, _Remote_, and fill the form:+For Android >= 11, first find the listening port:++```bash+adb jdwp+# press Ctrl+C to interrupt+```++Then redirect the resulting PID:++```bash+adb forward tcp:5005 jdwp:XXXX # replace XXXX+```++In Android Studio, _Run_ > _Debug_ > _Edit configurations..._ On the left, click+on `+`, _Remote_, and fill the form:- Host: `localhost`- Port: `5005`