Accessing ADB Shell From VM or Networked Device
In case you intent to run ADB commands on a VM, or from a different
machine, then the one running the Android emulator or connected to
the physical device, there are some steps that need to be done. I am
currently using Windows OS and a Kali VM. Please find instructions
below for that setup:
- Make sure the VM/networked machine is able to ping the machine connected to the Android device.
-
Start ADB server for the host machine to listen for remote
commands:
adb -a nodaemon server
-
If you receive an error stating that the port is already in
use, kill the ADB process and try starting the server again:
taskkill /f /t /im adb.exe
-
When the server is running, list the emulators and start the
desired one from Android Studio or the command line:
emulator -list-avds
emulator -avd Pixel_5_-Rooted -writable-system -no-snapshot
-
From the networked machine or VM, run the following command
to connect to the emulator via the newly opened port:
adb -H IP_FROM_HOST_RUNNING_ADB_SERVER -P 5037 shell
-
Install an apk with:
adb -H IP_FROM_HOST_RUNNING_ADB_SERVER -P 5037 install app_name.apk