Sometimes when developing embedded software on a Windows machine from a containerised Linux host, i.e. within a Dev Container, it can help to talk to the embedded device using the Android Debug Bridge (ADB) but indirectly via Windows.
Latest ADB, Docker Internal
Download the latest version of the Android platform tools and unzip them somewhere. Link the adb tool to somewhere that your shell can find. Run the following from within the dev container.
wget https://dl.google.com/android/repository/platform-tools-latest-linux.zip
unzip platform-tools-latest-linux.zip
ln -sf /path/to/platform-tools/adb ~/.local/bin/
Do not forget the final slash when sym-linking.
Now connect to the Android shell using the special host.docker.internal hostname, as follows.
adb -H host.docker.internal shell
Presto! It connects from the dev container, through the Windows ADB host to the Android device.
Explanation
The development container does not run the ADB server itself. Instead, it connects to the ADB server running on the Windows host, using host.docker.internal as the ADB hostname. The -H option overrides the default localhost; the default port remains the same 5037.
The indirect approach outlined above makes some important assumptions:
- Linking to
~/.local/bin/assumes that the LinuxPATHcarries that directory. The user’s~/.profiletypically sets up the PATH so it includes the user’s privatebinif it exists. - The ADB client and server need the same version; connection typically fails otherwise. Make sure that
adb --versiongives the same answer for Linux as well as Windows. Align the versions if not already match. It might be easiest to installadbon Windows using Chocolatey and then match the same version within the Dev Container.