@@ -18,7 +18,6 @@
 #define SC_SERVER_FILENAME "scrcpy-server"
 
 #define SC_SERVER_PATH_DEFAULT PREFIX "/share/scrcpy/" SC_SERVER_FILENAME
-#define SC_DEVICE_SERVER_PATH "/data/local/tmp/scrcpy-server.jar"
 
 #define SC_ADB_PORT_DEFAULT 5555
 #define SC_SOCKET_NAME_PREFIX "scrcpy_"
@@ -117,7 +116,7 @@ sc_server_params_copy(struct sc_server_params *dst,
 }
 
 static bool
-push_server(struct sc_intr *intr, const char *serial) {
+push_server(struct sc_intr *intr, uint32_t scid, const char *serial) {
     char *server_path = get_server_path();
     if (!server_path) {
         return false;
@@ -127,7 +126,16 @@ push_server(struct sc_intr *intr, const char *serial) {
         free(server_path);
         return false;
     }
-    bool ok = sc_adb_push(intr, serial, server_path, SC_DEVICE_SERVER_PATH, 0);
+
+    char *device_server_path;
+    if (asprintf(&device_server_path, "/data/local/tmp/scrcpy-server-%08x.jar",
+                 scid) == -1) {
+        LOG_OOM();
+        free(server_path);
+        return false;
+    }
+    bool ok = sc_adb_push(intr, serial, server_path, device_server_path, 0);
+    free(device_server_path);
     free(server_path);
     return ok;
 }
@@ -209,13 +217,20 @@ execute_server(struct sc_server *server,
     const char *serial = server->serial;
     assert(serial);
 
+    char *classpath;
+    if (asprintf(&classpath, "CLASSPATH=/data/local/tmp/scrcpy-server-%08x.jar",
+                 params->scid) == -1) {
+        LOG_OOM();
+        return SC_PROCESS_NONE;
+    }
+
     const char *cmd[128];
     unsigned count = 0;
     cmd[count++] = sc_adb_get_executable();
     cmd[count++] = "-s";
     cmd[count++] = serial;
     cmd[count++] = "shell";
-    cmd[count++] = "CLASSPATH=" SC_DEVICE_SERVER_PATH;
+    cmd[count++] = classpath;
     cmd[count++] = "app_process";
 
 #ifdef SERVER_DEBUGGER
@@ -388,6 +403,7 @@ execute_server(struct sc_server *server,
     for (unsigned i = dyn_idx; i < count; ++i) {
         free((char *) cmd[i]);
     }
+    free(classpath);
 
     return pid;
 }
@@ -937,7 +953,7 @@ run_server(void *data) {
     assert(serial);
     LOGD("Device serial: %s", serial);
 
-    ok = push_server(&server->intr, serial);
+    ok = push_server(&server->intr, params->scid, serial);
     if (!ok) {
         goto error_connection_failed;
     }