Skip to content

Instantly share code, notes, and snippets.

@syneart
Created January 12, 2021 07:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save syneart/3c6f03e40dba88dc367164b91b2c532f to your computer and use it in GitHub Desktop.
Save syneart/3c6f03e40dba88dc367164b91b2c532f to your computer and use it in GitHub Desktop.
Android debugging over WiFi (use adb)
#!/bin/bash
# This shell script is made by SyneArt <sa@syneart.com>
# Android Studio default path on Mac
adb=~/Library/Android/sdk/platform-tools/adb
function connect() {
device_id=$1
device_ip=`${adb} -s ${device_id} shell ip -f inet addr show wlan0 | grep -e "[0-9].*\/[0-9]*" | awk '{ print $2 }' | sed 's/\/[0-9]*//'`
echo "Android device id: ${device_id}"
${adb} -s ${device_id} tcpip 5555
${adb} connect ${device_ip}
}
while IFS= read -r line; do results_device_id+=("$line"); done < <(${adb} devices | grep -v "devices\|:" | grep "device\|offline" | cut -f 1)
[[ "${#results_device_id[@]}" -eq "0" ]] && echo "No any android devices need to switch to WiFi debug mode!"
for ((k=0; k<"${#results_device_id[@]}"; k++))
do
connect ${results_device_id[$k]}
done
@syneart
Copy link
Author

syneart commented Jan 12, 2021

Use below command to download the latest script on your own Unix operating system.
wget https://gist.github.com/syneart/3c6f03e40dba88dc367164b91b2c532f/raw/deviceConnect2Wifi.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment