Activate ADB wireless without USB connection to the device - android

I found several isntructions to activate ADB over wireless network instead USB connection (like this) but I have a problem: my device has the USB port broken.
I cannot execute adb tcpip 5555 because that, so I need to activate ADB over wireless if I want to use ADB to control the device.
Is there any way to do that without rooting the device? I tried several commands on a terminal emulator, but I didn't accomplish my objective.
Any proposal on that?

I have managed to do this using ssh with the following script. It might require some small adjustments (our platform is using systemctl, for one, so you might need to change those calls).
#/bin/bash
if ! command -v sshpass &> /dev/null
then
echo "sshpass could not be found. Please install it by running 'sudo apt install sshpass'"
exit
fi
IP="192.168.0.111"
USERNAME="user"
PASSWORD="password"
if [ $1 -a $1 == "disable" ]
then
read -n 1 -s -r -p "To disable adb over WiFi please plug in the USB cable and press any key."
adb disconnect $IP
adb kill-server
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $USERNAME#$IP "setprop service.adb.tcp.port -1; systemctl stop adbd; killall adbd &>/dev/null; systemctl start adbd &>/dev/null"
else
read -n 1 -s -r -p "To enable adb over WiFi please unplug USB cable and press any key."
adb kill-server &>/dev/null
sshpass -p $PASSWORD ssh -o StrictHostKeyChecking=no $USERNAME#$IP "setprop service.adb.tcp.port 5555; systemctl stop adbd; killall adbd; systemctl start adbd &>/dev/null"
adb kill- &>/dev/null
adb connect $IP &>/dev/null
fi
echo "Done!"

If your device is running Android 11 or above then you can accomplish this without initially needing to connect the phone to PC via USB as mentioned in the official Android developer site (link).
If the Android device is running Android 10 or below then there is no straightforward way without initially connecting USB (link).

Duplicate of
Run/install/debug Android applications over Wi-Fi?
Adding to it, if you install Android Studio Bumblebee version and your device OS is 11+,
there is a direct option to connect via Android Studio.
Here are the steps:
First, Connect your phone and machine on the same wifi network
on Phone:
Go to Developer Options -> Wireless Debugging -> Turn on the switch then tap on text Wireless Debugging
Select Pair device with QR code
on Desktop:
1.
Expand this drop down
Select Pair
Scan the QR code wait for some time and that's it!
Note: It disconnects frequently, has to be a bug which we should wait to get fixed

Related

How to connect multiple android devices with ADB over wifi

ADB is installed in the computer, and usb debugging is enabled on devices. Also I have connected one device over wifi successfully. How to connect more devices without having to mention the serial number of the device for every additional device with the -s flag like: adb -s <serial> tcpip <port>
Yes there is a way to do so without having to type the serial number.
Say you have 2 devices A (IP: 192.168.1.32) and B (IP: 192.168.1.33) that you want to connect to ADB over wifi:
Connect device A with a USB cable to the computer (but not B)
adb -d tcpip 5555
adb connect 192.168.1.32
Disconnect device A, and connect device B with a USB cable to the computer
adb -d tcpip 5555
adb connect 192.168.1.33
A slight change in the Abdul Wasae answer, based on my experience .
devices A (IP: 192.168.1.32)
devices B (IP: 192.168.1.33)
Connect device A with a USB cable to the computer (but not B)
adb -d tcpip 5555
adb connect 192.168.1.32
Disconnect device A, and connect device B with a USB cable to the
computer,This time you need to change the port !!
adb -d tcpip 5554
Here you need to specify port as well
adb connect 192.168.1.33:5554
I also have documented this here in more detail
Connecting multiple devices over wifi using adb
I have this problem long time ago so I decided to create this simple bash script.
Assuming that you already added the adb to the path:
export PATH=${PATH}:/home/YOUR-USERNAME/path/to/adb
You just need to follow this steps:
Run this commands: to create your script (typically, you want $HOME/bin for storing your own scripts)
cd ~
mkdir bin
cd bin
touch adb_connect
Open and copy the script using any editor like gedit.
gedit adb_connect
And make your file executable.
sudo chmod +x adb_connect
Modify your path to add the directory where your script is located:
export PATH=$PATH:$HOME/bin
Finally, now connect your device using USB and run the script:
adb_connect
Your device must be connect now, disconnect the USB cable and repeat steps 5 and 6 to add more devices. If a successful connection occurs, it will have this output:
Connecting to LGV498bdcb2c5
restarting in TCP mode port: 7105
connected to 192.168.20.105:7105

Trying to setup ADB wireless, stuck at "adb tcpip 5555"

I used to be able to setup wireless ADB no problem (plug in, adb tcpip 5555, adb connect ), now it gets stuck indefinitely during the "adb tcpip 5555" command. Wired adb still works fine, so does setting up wireless ADB through apps in play store, just not via cmd. Between wireless working and now not working, I did a bunch of things so any of them may or may not be the problem:
1) Reformatted computer (Same OS)
2) Redownloaded the SDK needed for Android Development
3) Went from ParanoidAndroid to GPE on my HTC One.
Anyone have any idea what the problem is?
You can emulate what apps do with these steps on your device with root and android terminal emulator:
$ adbd stop
$ setprop service.adb.tcp.port 5555
$ adbd start
Then use adb connect XXX.XXX.XXX.XXX where XXX.XXX.XXX.XXX is your ip address found from:
$ ifconfig wlan0 | awk '/inet addr/ {print $2}' | cut -d: -f2
You can check if your connection is establed using netstat | grep 5555. You should see a tcp entry with your ip address and port for adb connectivity.
If your device is rooted then it is very simple to establish a wireless connection, you don't even need a USB cable. Download this app from Google Play https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb&hl=en
It worked for me at least, and as can be seen from the app rating it works for almost all.
-----Enter the command adb kill-server at command prompt-----
C:>adb kill-server
-----Enter the command adb devices-----
C:>adb devices
List of devices attached
daemon not running; starting now at tcp:5037
daemon started successfully
DeviceID device
-----DeviceID is the unique ID of connected device-----
-----Enter the command adb tcpip 5555-----
C:>adb tcpip 5555
restarting in TCP mode port: 5555
-----will see the response as given above -----
-----Enter the command adb connect 1.1.2.2-----
-----1.1.2.2 is the mobile device IP-----
C:>adb connect 1.1.2.2
connected to 1.1.2.2:5555
-----will see the response as given above -----
-----Now u can use 1.1.2.2:5555 ID as wireless to connect device-----

ADB tcpip command without cable

I need remote ADB shell..
I know that we have to issue "ADB tcpip ".. to change ADB server to TCP listening mode.
But, the problem is that my phone is not rooted, and I do not have USB cable.
I can't issue tcpip command since I do not have USB cable,,
I can't change default.prop file as the phone is not rooted.
Is there any other ways to change ADB server to TCP listening mode???
I found an articel that says you can execute setprop persist.adb.tcp.port 5555 to make tcpip mode autostart after reboot.
The problem is, you must run this command as root.
On my device unfortunally the command su doeas not exist.
Here is the orginal Permanent network debugging on android
EDIT: I discovered, that the su command is only available when your device is rooted.
So the solution only works when you have a rooted phone
The simple answer is: no, you can't.
As you said, you can't access the prop file and don't have a cable to change with ADB. The only way is you find the port via an Android terminal emulator (a.k.a Termux)
For anyone looking for a better answer:
YES, YOU CAN!!
When you try to execute "adb tcpip 5555" without an USB cable, it returns:
"error: no devices/emulators found"
Emulators?? After googling I found the way and made a batch file that connects my device directly through WIFI, no cables needed at all:
set /p ip= Device IP:
:CONNECT
if "%CD%"=="C:\" goto ROOT
cd ..
goto CONNECT
:ROOT
cd ...Android\Sdk\emulator
echo.
echo Starting emulator...
start /MIN emulator -avd Nexus_5X_API_29_x86 -no-window
(you can check other avaliable devices with "emulator -list-avds")
cd ..
cd platform-tools
adb wait-for-device
echo.
echo Emulator started.
echo Connecting with device...
adb tcpip 5555
adb connect %ip%
echo.
echo Closing emulator...
(you need it just to be able to execute "adb tcpip 5555")
adb -s emulator-5554 emu kill
(you can check the name with "adb devices")
To enable wireless debug need to configure the ADB command. (in mac os)
Step1:- First of all need to enable adb command. (check SDK tool and install command-line tools)
Step2:- connect the device with a USB cable after that run the below command.
command: adb devices
the above command will show a list of connected mobiles.
Step3:- after that, we need to configure TCPIP protocol:
e.g : adb tcpip 5556
Step4:- Run command to connect the device.
command: adb connect your_ip:port_address
eg:- adb connect 192.168.1.152:5556
If you are using the stock android os system, then you can enable remote debugging in Settting -> developer options.

Android - adb tcpip error

I want to connect to the Android device using adb over the network. I am familiar with How can I connect to Android with ADB over TCP? and with https://developer.android.com/guide/topics/usb/index.html and follow the guidelines. Specifically, I did the following:
# adb kill-server
# adb tcpip 5555
* daemon not running. starting it now on port 5037 *
* daemon started successfully *
restarting in TCP mode port: 5555
# adb connect 192.168.1.101:5555
unable to connect to 192.168.1.101:5555:5555
Due to the last error, I also tried
# adb connect 192.168.1.101
unable to connect to 192.168.1.101:5555
I also tried to restart the device itself, but it did not help.
Any reason why it does not work?
Update: To clear any doubts, I am sure that this is my device internal IP address.
I've been having the same issue with my unrooted device. And contrary to popular belief it seems that adb tcpip <port> requires either an emulator or a debug build or root privileges; at least according to the source code.
master branch: https://github.com/android/platform_system_core/blob/master/adb/adb.c#L898 look at should_drop_privileges which prevents https://github.com/android/platform_system_core/blob/master/adb/adb.c#L966 adb_main to open a TCP/IP socket connection.
In older branches the logic for identifying the privileges of adbd were in adb_main itself. See: https://github.com/android/platform_system_core/blob/froyo-release/adb/adb.c#L860
So, to further prove that adbd won't enter TCP/IP mode (even though adb tcpip gives out no errors), look at the following:
adb shell getprop | grep 'ro.secure\|debuggable\|qemu', output for my device:
[ro.secure]: [1]
[ro.debuggable]: [0]
This does not meet the conditions of being able to get a secure value of 0 in adbd, since I'm not running an emulator (which needs TCP/IP by default), I'm not running a debuggable build of Android, and I'm not root.
Furthermore if you issue an adb shell netstat command you'll see that there's nobody listening on port 5037 or 5555 or whatever else you supplied to the tcpip command as expected from an adbd running in TCP/IP mode.
Hope this helps, good luck!
The ability to restart adbd using tcpip transport can vary from device to device. Without knowing exactly which device you're using it's very difficult to know the exact cause.
I tested "adb tcpip 5555" on a Galaxy Nexus (takju) running 4.2.1 and found it to work. I also tested on a couple other devices and those did not work.
I managed to get it to work using root access on a Motorola Droid 3. Note that ro.secure=1 and ro.debuggable=0 still. I simply by manually set service.adb.tcp.port" to "5555" as such:
devbox:~/droid3$ adb shell
shell#cdma_solana:/$ getprop | grep 'ro.secure\|debuggable\|qemu'
[ro.secure]: [1]
[ro.debuggable]: [0]
shell#cdma_solana:/$ su -c 'setprop service.adb.tcp.port 5555'
shell#cdma_solana:/$ exit
devbox:~/droid3$ adb tcpip 5555
restarting in TCP mode port: 5555
devbox:~/droid3$ adb connect 172.16.0.14
connected to 172.16.0.14:5555
devbox:~/droid3$ adb -s 172.16.0.14:5555 shell
shell#cdma_solana:/$
Although I specified 5555 when running "adb tcpip" it gets ignored by the device. It seems that this particular device does not have the required access to set the "service.adb.tcp.port" property without root.
Similarly, you can go back to USB as such:
shell#cdma_solana:/$ getprop | grep adb
[persist.service.adb.enable]: [1]
[ro.sys.atvc_allow_all_adb]: [0]
[persist.adb.tcp.port]: []
[init.svc.adbd]: [running]
[service.adb.tcp.port]: [5555]
shell#cdma_solana:/$ su -c 'setprop service.adb.tcp.port ""'
shell#cdma_solana:/$ exit
devbox:~/droid3$ adb -s 172.16.0.14:5555 usb
restarting in USB mode
devbox:~/droid3$ adb shell
shell#cdma_solana:/$
The reasons that this might not work on other devices vary.
On the Galaxy Nexus I tested, the shell user is able to set the "service.adb.tcp.port" property. It's not clear why this differs at this time.
Interestingly it seems the droid3 will not continue to listen on USB if you enable TCPIP. However, the Galaxy Nexus will.
Hope this helps..
PS. See also: How can I connect to Android with ADB over TCP?
I also met same scenario as your, TCPIP setup succeseed, but adb connet failed. I finally found it's my network problem, the ping also failed under that scenairo.
After i made the ping works, the adb connect works as well. So, my suggestion is to check your network environment.
Hi there I know this is an old question but I was having the same problem. I am not sure it is the same case for you but the problem for me was that I was connecting my Android device through a USB expansion, as soon as I connected the Android device directly to the USB port in my MAC it worked.
Just to clarify try to connect the Android device directly to the computer or try switching the USB port.

Getting Error while configuring ADB

Trying to configure ADB so that I can debug it via wifi, I have checked on Google but not getting proper resolution.
Tell me what to enter in port address, device ip.
Moreover setprop service.adb.tcp.port command is running when i give space between set and prop, bit confuse...
Seeking for help
I got the following article, and wanted help in the same context.
disconnect device from usb then tell it to listen on 4455
adb tcpip 4455
restarting in TCP mode port: 4455
connect to the device using a specified ip:port. my device is using wifi
adb connect 192.168.1.103:4455
connected to 192.168.1.103:4455
now do normal adb commands over tcp
adb shell
when your done, you can put it back in USB mode
adb usb
restarting in USB mode
Help me
These are commands for the shell of the android device, not for the host system.
Type adb shell to get the device's shell and then enter them. If you get back to the windows shell prompt you are in the wrong place.
However those commands may not be effective on a secured device anyway.
setprop is an Android command and is meant to be used in a terminal after su on the device (you can do adb shell setprop ... but when you adb shell stop adbd you'll loose your device connection). The easier way if already connected via USB is adb tcpip 8600 and then adb connect IP_OF_PHONE:8600 -- but this will only work if adb shell will get you a root prompt (starts with # and not $). Be aware that anyone on your wifi network can access your device!

Categories

Resources