Jump to content
Guest

Easy way to keep your Smarphone (Android or similar) connected in your IDE same in Debug - No more Losted Device / Connection

Recommended Posts

Guest

GOODBYE LOST DEVICE / CONNECTION ON ANDROID DEBUG APPS

 

  1. You need be in the same network, PC and Android device, of course!
  2. Active your "Developer Options" in your Android! Configure on-device developer options | Android Developers
  3. Connect the device via USB and make sure debugging is working;
  4. On CMD (not necessary ADMIN user status), type command: adb tcpip 5555. This makes the device to start listening for connections on port 5555; - you can use another avaliable!
  5. Look up the device IP address with adb shell netcfg or adb shell ifconfig with 6.0 and higher;
  6. You can disconnect the USB now;
  7. type: adb connect <DEVICE_IP_ADDRESS>:5555. This connects to the server we set up on the device on step 2;
  8. Now you have a device over the network with which you can debug as usual.

 

  • To switch the server back to the USB mode, run adb usb, which will put the server on your phone back to the USB mode.
  • If you have more than one device, you can specify the device with the -s option: adb -s <DEVICE_IP_ADDRESS>:5555 usb.
  • No root required!
  • To find the IP address of the device: run adb shell and then netcfg. You'll see it there.
  • To exit of shell, type exit.
  • To find the IP address while using OSX /MSWindows (too) run the command adb shell ip route. <--- works better!

 

WARNING: leaving the option enabled is dangerous, anyone in your network can connect to your device in debug, even if you are in data network.

  • Do it only when connected to a trusted Wi-Fi and remember to disconnect it when done!
  • Sergei suggested that line 2 should be modified, commenting: "-d option needed to connect to the USB device when the other connection persists (for example, emulator connected or other Wi-Fi device)".
  • This information may prove valuable to future readers, but I rolled-back to the original version that had received 178 upvotes.
  • On some device you can do the same thing even if you do not have an USB cable:

 

image.thumb.png.651224ecfee0c267b12a4eebd927dd45.png

 

  • It should show the IP address (if not, no problem - your edition can dont show this info)
    • adb connect <DEVICE_IP_ADDRESS>:5555
  • Disable the setting when done

 

 

If you dont understand, here a summary:  TESTED AND REALLY WORKS!

  1. Connect your USB cable between PC and Android smartphone
  2. type the command: adb tcpip <<port_number>> ---> if the port is not accessible, the ADB try another and show to you!
  3. Disconnect your USB cable, it's not usable now!
  4. type the command: adb connect <<ip_address_of_your_device_in_your_wifi_network>>:<<port_number_showed_by_adb_above>>
  5. It's ready!
  6. Now you can deploy your app using your RAD Studio IDE like before when using USB cable!
  7. If you want come back use USB cable type command: adb usb
  8. Dont forget, read above the warning about using this way access your device using a open-network!
  9. On your device, deselect the "Developer Options" to avoid using advanced options like this.

 

  • the ADB.exe is in your Platfom SDK Windows folder, in "..\platform-tools\adb.exe"
  • You can also set an environment variable called ADBHOST with the IP address and adb will attempt to connect to that ip.
  • Now I am not sure if DDMS can connect to the device over tcpip, but if adb can, and ddms uses adb to connect, it should be possible.

 

SOURCE: a summary of internet posts include StackOverFlow

 

hug

Edited by Guest

Share this post


Link to post
4 hours ago, emailx45 said:

Disconnect your USB cable, it's not usable now!

Actually, it is usable; at least for me (Pixel 3a, Android 11). It seems tcpip mode is in addition to usb mode. It appears that using

adb usb

 just removes tcpip mode.

Edited by Dave Nottage

Share this post


Link to post
Guest

Not sure if this belongs here but i want to add something and sorry if it is off-topic or irrelevant.

 

Never faced such thing on my PC and Android phone, i mean the offline and disconnected and delays, but a friend was having really bad time and it is frustrating, trying my phone on his laptop, did the same, so we did compared everything we could think of and reinstalled drivers, software ... yet the problem still on his device, just then i occurred to me if the fact i have desktop and he is using laptop could be the problem, se we went after the power settings on his device and the problem was solved.

Now i can't remember which power profile solved this and which setting, but this might be helpful https://www.windowscentral.com/how-prevent-windows-10-turning-usb-devices and we didn't isolate one thing to figure it back then as we were bored and tired.

 

Check you your power settings and try to tweak it to prevent USB and other devices suspension, and on side note this can be generating very ugly and hard to track bug in TCP connections in very low traffic environment as OS might put the network card to sleep.

Share this post


Link to post
10 hours ago, emailx45 said:

WARNING: leaving the option enabled is dangerous, anyone in your network can connect to your device in debug, even if you are in data network.

Thanks for the tutorial, I'm a huge fan of detailed instructions 👍

Good to point out above warning too, I'm afraid not many people are aware of this.

(By the way: This is also true when you charge your phone on public USB-sockets, better deactivate ADB before ).

 

Regarding the ADB over Wifi, maybe there is an option to restrict ADB operation only from a specific IP-Adress ?

I have never checked that, but it could give much more security if you can allow only point-to-point connections.

 

Share this post


Link to post
Guest

One NOTE:

YOU DONT NEED WIFI BY INTERNET!

 

NO NO NO.

 

Remember, many devices can create a "hotspot" to broadcast wifi signal  like your smartphone (itself) using create/activate "Router Wifi", if you have it.

 

include that is possible use it like a FTP portable between smartphone and your pc, for example.

 

using WinSCP app for MSWindows, for example, you can talk with your smartphone easy easy. bi-direction.

 

 

Share this post


Link to post
Guest
3 hours ago, Rollo62 said:

Regarding the ADB over Wifi, maybe there is an option to restrict ADB operation only from a specific IP-Adress ?

 I have never checked that, but it could give much more security if you can allow only point-to-point connections

uhmmmmm let's thinking....

 

if your network allow access restrict to an address, for example, using a login (user and password), then you have a chance!

 

a Firewall maybe can help... a proxy, etc...

in a switch you can create a virtual.networks, then, address diferents. etc...

 

but hacker is hacker, on the end.

Share this post


Link to post

@emailx45

All right, hackers welcome.

I was thinking smalller, in the local intranet first, there I usually use development phones, that were not normally intended to be in the wild.

What I was thinking of was a kindof whitelisting the ADB connection to only one IP-adress,

I have the gut feeling that there is already something in the Android ecosystem, we only need to dig it out.

Edited by Rollo62

Share this post


Link to post
Guest
28 minutes ago, Rollo62 said:

I have the gut feeling that there is already something in the Android ecosystem, we only need to dig it out.

remember: when USB connection is activated in Android (maybe in anothers smatphones, I dont have it), it ask you if "YOU TRUST" the ID-Device trying connect it... 

then, this is a first "fire-WOW" 🙂 ---  ... using USB cable ... where all begin...

then, later, you can use "wifi" method.

Share this post


Link to post
Guest
On 12/10/2020 at 4:40 AM, Kas Ob. said:

Never faced such thing on my PC and Android phone, i mean the offline and disconnected and delays, but a friend was having really bad time and it is frustrating, trying my phone on his laptop, did the same, so we did compared everything

hi @Kas Ob.

the "big" problem with USB Cable and smartphone (at least, in my Moto G4 with Android 7.0 Nougat), is:

  • the "POWER RECHARGE" by USB from PC....
  • in my case, the MSWindows stay like a "crazy" ... ON / OFF ... ON/OFF connection USB for "data" = same in smartphone if my battery is < 50% charge.
    • in MSExplorer, I was watching the smartphone drive appear and disappear ... (like a toothless madman running down the street ...) in screen because this behavior == recharging the smarphones by USB from PC, same that is not my intent in this moment, because I was actually trying to send the Delphi app to Android to debug it!
  • then, in this case, use "wifi" method I dont have more this problem
Edited by Guest

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×