The data line is a grinding goblin
Mobile terminal development, especially Android, emulator card, also relatively easy to eat memory, so I am almost the computer with real machine debugging run, the connection link is a data line.
There is nothing wrong with a data wire, but what is wrong is that it is a physical wire that can be touched by the body. A lot of times, when YOU lift your hand and accidentally touch it, the connection will be broken. Imagine, when you have written a great code, ready to run it and see the effect, you do not find the connection device, this happens many times, the inner language is very unhealthy.
So, I want to share with you a practical tips, to get rid of the data line this grinding goblin.
How to get rid of goblins
The procedure is very simple, only three steps, but there are two prerequisites.
1. ADB environment has been installed on the computer. The majority of people who care about me are Android developers, so this premise should be met fairly well.
2. Ensure that the IP addresses of mobile phones and PCS are on the same network segment. As long as the network is connected to the same LAN, it is generally in the same network segment.
Step1- connect your computer to your phone
The first step still requires a data cable to connect the computer to the phone. This step ensures that the connection is successful, and I confirm this by looking at the Android Studio connection Settings list or the ADB Devices command.
If you don’t see the device, check if the developer option -USB Debugging is turned on on the phone.
Step2- set port 5555
After successful connection, the second step is to set up the WIFI debugging port 5555 of the mobile device, and then the teenager, you can unplug the data line, the third step has been able to operate under the condition of wireless.
On your computer’s command line window, type the following command:
adb tcpip 5555;
Copy the code
Below is a screenshot of the result, with a message indicating that the port has been reset.
Step3- connect the IP address of the mobile phone
In the final step, a connection command is required, as follows, but this command requires the IP address of the phone.
Adb connect < IP address of device to connect >;Copy the code
There are many ways to get your phone’s IP address, but here are two of my own.
The first is to run the following command to view the IP address of the connected device.
adb shell ifconfig wlan0;
Copy the code
The IP address of the device is in the standard red box below.
The second is to operate in the mobile phone, open the Settings – Wlan-Configuration page, you can see the current IP.
Once you have the device’s IP, use the ADB Connect command to connect the computer to the phone.
Now that the process is complete, run ADB Devices again to get the following result. It was successfully connected to the computer and mobile phone without a data cable.
The difference is that APU7N16304003941, the unique identifier of the previous device, is changed from the random sequence number generated by ADB to the specific network address of IP:port, 192.168.0.126:5555.
Isn’t that amazing?
Realize the principle of
The magic is wireless communication, a form of communication that takes advantage of the fact that radio signals can travel through free space to exchange information. Of course that’s not the point, I’m being clever, but the point is the way ADB works and the two connection modes.
In the daily development process, I have been using ADB, but many people do not know much about it, such as me, now let’s have a brief review.
ADB, short for Android Debug Bridge, is a general command line tool. It can be found in android_SDK /platform-tools and can be used to directly manipulate various Android devices. For example, APK installation and uninstallation, view the package name and signature information of the installed applications on the phone, and so on.
ADB is actually divided into three parts:
- Client ADB Client: Runs on a PC. It is used to send commands, and the ADB command we entered earlier in this article is sent from the client environment.
- Server ADB Server: Runs on a PC. Manages the communication between clients and background programs.
- Background program ADBD: Runs on Android devices. Run commands from adb Server as a backend service.
Here is a simple diagram of the relationship between the three:
ADB supports two ways to connect to PC, USB and TCP/IP. USB is used for data cable connection, and TCP/IP is used for WIFI connection we introduce this time.
Adbd on mobile phone uses USB mode by default. If you want to use WIFI connection, you need to manually turn on 5555 listener. So we have adb TCPIP 5555 above; This operation step.
In fact, setting the port 5555 listener is essentially setting the value of service.adb.tcp.port in adBD. When adBD is started, this value is checked first, and if set, TCP/IP is used as the connection mode. If not, select USB as the connection mode.
If the device has root privileges, you can do without a data cable, and it is said to be possible to set it from the command line on the phone. There is no root device in hand, can not practice. If you’re interested, you can try it.
The following commands are used:
/ / adb shell below to perform the command setprop service. The adb. TCP. The port 5555 ps | grep adbdkill-9 {adBD process id}Copy the code
All right, that’s it! Friends, try this method, experience from wired to wireless feeling, very awesome.
To tell you the secret, the WIFI mode can connect to multiple phones, no longer need to be afraid of the USB port on the computer is not enough. You can also connect the test girl’s device to the development computer, and install the latest APK at any time, which is also a successful show of operation!
Well, see you next time. Don’t forget to like the author or share it with your friends!
PS:
Through the comments, I found that there are several places in the article that are not clearly described. Here are some additional points:
-
Not every time you connect, you need to plug in the data line, theoretically only for the first time.
The article said that the data line was inserted in order to set up the port to allow Wi-Fi debugging. So if the connection breaks during wi-fi debugging, just run the connect command again.
Why say theoretically, because in the comment “designer Daniel Wu” classmate put forward “most domestic mobile phone may appear the port is not 5555; Even if you set it to 5555, it changes back when you restart the phone;” I haven’t encountered this situation yet, but the students I met need to reconnect the data line and set the port number.
-
Regarding power consumption and charging, I have experienced this problem. Because a few days ago, found the test machine unexpectedly prompt power shortage! “In the wired state, the power was automatically replenished when no power was available. The test machine was almost always fully charged, and was suddenly prompted that the power was low, which was really unexpected. There’s no exact estimate of the power consumption, but I think we’re pretty good at it.
The battery’s out. Let’s just charge it.
-
Android Studio can set up related plug-ins, such AS: ADB WIFI/ADB WIFI Connect, support WIFI debugging, the principle of not studied is not clear, there is a GUI page for operation, it is very convenient to use. See everyone needs, like to use what, use what, meet the demand can.