0

I am running multithreaded emulation and have more than one emulator.

Problem : In ADB They are all named the same so I only see one device

how do I change the names or send command to them seperately ?

EDIT :

Sorry guys I didn't see it had not so much information and to be honest I wasn't expecting to get answers

-> I'm running android x86 on virtualbox and ADB to control it

(I killed served and checked devices again for every situation)

Here you can see emulator-5554 is available when ANDROID 1 vm is running

Here you can see emulator-5554 is available when ANDROID 2 vm is running

Here you can see emulator-5554 is available when ANDROID 1 vm is running AND ANDROID 2 is running

So what I want to do is using controling both or more using python with this script

import subprocess
import time
import threading


def run_adb_command(command):
    process = subprocess.Popen(["adb", command], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    output, error = process.communicate()
    return output, error

run_adb_command("kill-server")

def start_virtual_devices():
    for i in range(1, 21):
        device_name = "Android " + str(i)
        subprocess.run(["VBoxManage", "startvm", device_name, "--type", "headless"])
        time.sleep(2)

def get_connected_devices():
    output, error = run_adb_command("devices")
    devices = []
    for line in output.decode().splitlines():
        if "\tdevice" in line:
            device_id = line.split("\t")[0]
            devices.append(device_id)
    return devices

def set_proxy_and_login(device, proxy, login):
    run_adb_command("-s {} shell settings put global http_proxy {}".format(device, proxy))
    # Set login in the app using adb commands
    

proxies = [] # List of proxy strings in the format "host:port"
logins = [] # List of login strings in the format "username:password"

start_virtual_devices()
devices = get_connected_devices()

if len(devices) == 0:
    print("0 devices are connected".format(len(devices)))
    exit()
print(str(len(devices))+" devices are connected".format(len(devices)))
for i in range(len(devices)):
    #device = devices[i]
    #proxy = proxies[i % len(proxies)]
    #login = logins[i % len(logins)]
    #set_proxy_and_login(device, proxy, login)
    print("Thread start")

print("All threads have finished execution")

This script basically just create VMs, wait for 30s so they load, look for devices in ADB and attribute proxy and device-id to each thread to control VMs with ADB

But the problem is since they are all named the same, ADB doesn't dissociate them and only count 1 everytime. How can I make them not all named the same ? I tried controlling them separately using IP:PORT but it doesn't seem to work or maybe I'm just super bad at it.

All my VMs are port redirected like that

I know for a fact it's possible since I know someone who did it but doesn't want to help me out to do it.

His program is compiled. So I looked at his VMs configuration and saw that

They all have a different host port

So I tried changed it as I thought it would change the device name but ADB devices just doesn't see it anymore.

So I had the good idea to install ADB by myseld on the computer and check for the name of the VMs but the installed ADB doesn't see any Android emulator connected. So Maybe I have to change some ADB settings to see and control them separately ?

here when device not showing on ADB on another computer

After looking on forums I found out emulator-5554 is named for the port of the emulator so if I can understand how to change the port or settings on ADB maybe I can have list of devices like that : Emulator-5554 Emulator-5553 Emulator-5552

and control them using the -s command

Thank you for your time and help, I'm very confused on what to do to solve the issue.

  • Possibly related: [How can I deploy and execute an application on a device connected to a remote system?](https://stackoverflow.com/q/27245597/295004) Otherwise you should detail what you are doing/what you've tried. Please don't assume that anyone looks at your past questions to get context. – Morrison Chang Feb 14 '23 at 05:10
  • I assume whey you say "all named the same" you are talking about the output of `adb devices`? Please see also https://stackoverflow.com/q/2214377/150978 – Robert Feb 14 '23 at 08:06
  • Providing the output of `adb devices` would help us understand, and you can add something about *multithreaded* part which is not clear. Multiple emulators are multiple proceses, in case you are referring to that. – Diego Torres Milano Feb 15 '23 at 06:49
  • Sorry guys, I uploaded pictures, code and VMs configuration, thank you very much for your time – Thomas Decroix Feb 15 '23 at 10:23
  • Please do not post console output like those of `adb devices` in screenshots (especially not in full-screen screen shots. Is there any reason why you use VirtualBox and configure everything manually instead of using Android emulator for SDK (which does all this automatically)? – Robert Feb 15 '23 at 10:55
  • I posted them to show the VMs running in the background I don't really know how to use android emulator I think I just got used to use virtualbox and my friend did it on virtualbox so I naturally chose the same – Thomas Decroix Feb 15 '23 at 12:56

0 Answers0