Linux

Access adb devices from WSL

2022-02-11  本文已影响0人  JaedenKil

While there is an android device connected to windows PC via usb adb, the device can be accessed from windows terminal:

$ adb devices
adb server version (39) doesn't match this client (41); killing...
* daemon started successfully
List of devices attached
2022010704      device

The device cannot be accessed from WSL:

$ adb devices
adb server version (39) doesn't match this client (41); killing...
* daemon started successfully
List of devices attached
2022010704      device

Steps:

  1. Install adb for WSL
    In WSL terminal, install adb
sudo apt update
sudo apt install adb
  1. Check WSL adb version & windows adb version
# Windows
$ adb version
Android Debug Bridge version 1.0.41
# WSL
madhatter@xxx:/$ adb version
Android Debug Bridge version 1.0.39
  1. Make sure the adb versions are the same, if not, upgrade one
    3.1 Download platform tools to windows: Search for "Download SDK Platform-Tools for Linux"
    3.2 Move the platform tools to desired location and unzip(Maybe sudo apt install unzip is needed)
# WSL
cp -r /mnt/c/Users/zzheng/Downloads/platform-tools_r32.0.0-linux.zip .
unzip platform-tools_r32.0.0-linux.zip

3.3 Check adb version

# WSL
madhatter@xxx:~/PlatformTools$ ./platform-tools/adb version
Android Debug Bridge version 1.0.41
Version 32.0.0-8006631
Installed as /home/madhatter/PlatformTools/platform-tools/adb

3.4 Link the new adb

# WSL
madhatter@xxx:~/PlatformTools$ ln -s ./platform-tools/adb /usr/bin/adb
ln: failed to create symbolic link '/usr/bin/adb': File exists

If the error msg is displayed, run the below command

# WSL
madhatter@xxx:~/PlatformTools$ sudo ln -sf ./platform-tools/adb /usr/bin/adb
[sudo] password for madhatter:

3.5 Update env var:

# WSL
export PATH=/home/madhatter/PlatformTools/platform-tools:${PATH}

# Update bashrc
vim ~/.bashrc
# Add the line to the end of the file
export PATH=/home/madhatter/PlatformTools/platform-tools:${PATH}
# source bashrc
source ~/.bashrc
  1. Check adb version
# WSL
madhatter@xxx:~/PlatformTools$ adb version
Android Debug Bridge version 1.0.41
Version 32.0.0-8006631
Installed as /home/madhatter/PlatformTools/platform-tools/adb
  1. Check adb devices
madhatter@xxx:/$ adb devices
List of devices attached
2022010704      device

Possible alternative method:

 mkdir -p /usr/local/android-sdk \
  && cd /usr/local/android-sdk/ \
  && curl -OL https://dl.google.com/android/repository/platform-tools-latest-linux.zip \
  && unzip platform-tools-latest-linux.zip \
  && rm -f platform-tools-latest-linux.zip \
  && ln -s /usr/local/android-sdk/platform-tools/adb /usr/bin/adb \
  && export PATH=/usr/local/android-sdk/platform-tools:${PATH} \
  && echo "export PATH=/usr/local/android-sdk/platform-tools:${PATH}" >> /etc/profile \
上一篇 下一篇

猜你喜欢

热点阅读