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.