Run/install/debug Android applications over Wi-Fi?

前端 未结 30 1731
[愿得一人]
[愿得一人] 2020-11-22 07:16

I thought there was a way to test your applications in development over Wi-Fi. Is this possible?

I\'d love to be able to untether my phone and develop wirelessly.

相关标签:
30条回答
  • 2020-11-22 07:54

    For Windows:

    Step 1. Make a batch file with the below commands and call the file w.bat.

    Step 2. Copy the below contents in w.bat, and save it in any of the folders which are in %path% of your Windows system

    echo ***Get phone in Wi-Fi mode***
    echo ***Get phone in Wi-Fi mode***
    
    adb devices
    echo ***Remove cable from the phone now***
    adb tcpip 9000
    
    adb connect 192.168.1.1:9000
    adb connect 192.168.1.2:9000
    adb connect 192.168.1.3:9000
    adb connect 192.168.1.4:9000
    adb connect 192.168.1.5:9000
    adb connect 192.168.1.6:9000
    

    //<-- Till here -->

    Step 3. Connect your phone and PC with a cable

    Step 4. Ensure the phone is in Wi-Fi mode

    Step 5. Remove the cable when the batch file tells you to

    Step 6. Type w.bat on the Windows prompt (start -> run -> type CMD, press Enter) (black screen is Windows DOS prompt), if you copied it in one of the path folders then you can run from anywhere, else run from the folder where you created this file.

    The output of the batch file will be something like this:

    C:\Windows\System32>w
    
    C:\Windows\System32>echo ***Get phone in Wi-Fi mode***
    ***Get phone in Wi-Fi mode***
    
    C:\Windows\System32>echo ***Get phone in Wi-Fi mode***
    ***Get phone in Wi-Fi mode***
    
    C:\Windows\System32>adb devices
    List of devices attached
    d4e9f06 device
    
    C:\Windows\System32>echo ***Remove cable from the Phone now***
    ***Remove cable from the Phone now***
    
    C:\Windows\System32>adb tcpip 9000
    restarting in TCP mode port: 9000
    
    C:\Windows\System32>adb connect 192.168.1.1:9000
    unable to connect to 192.168.1.1:9000:9000
    
    C:\Windows\System32>adb connect 192.168.1.2:9000
    connected to 192.168.1.2:9000
    
    C:\Windows\System32>adb connect 192.168.1.3:9000
    unable to connect to 192.168.1.3:9000:9000
    
    C:\Windows\System32>adb connect 192.168.1.4:9000
    unable to connect to 192.168.1.4:9000:9000
    
    C:\Windows\System32>adb connect 192.168.1.5:9000
    unable to connect to 192.168.1.5:9000:9000
    
    C:\Windows\System32>adb connect 192.168.1.6:9000
    unable to connect to 192.168.1.6:9000:9000
    

    Note 1: Find this in the output, (ignore all ->unable to connect<- errors)

    connected to xxx.xxx.x.x:9000
    

    If you see this in the result, just remove the cable from PC and go to Eclipse and run to install the app on the device; that should be it.

    Note 2: DISCONNECT OR TO SWITCH WIRELESS MODE OFF: Type the below command. It should say restarting in USB mode - at this stage PC and computer should NOT be connected with a cable:

    C:\Users\dell>adb usb
    restarting in USB mode
    

    Note 3: Steps to find the IP address of the phone (taken from Stack Overflow)

    Find IP address of MY PHONE:

    a. Dial *#*#4636#*#* to open the Testing menu.
    b. In the Wi-Fi information menu: click Wi-Fi Status
    c. Wi-Fi status can be blank for the first time
    d. Click Refresh Status
    e. In the IPaddr: <<IP ADDRESS OF THE PHONE IS LISTED>>
    

    Note 4: My Phone Wi-Fi connection IP address range typically is as the mentioned IP addresses below,

    192.168.1.1

    192.168.1.2

    192.168.1.3

    192.168.1.4

    192.168.1.5

    192.168.1.6

    Note 5: if you get any other sequence of IP addresses which keep getting reassigned to your phone, you can just change the IP address in the w.bat file.

    Note 6: This is a brute-force method, which eliminates all manual labor to keep finding IP address and connecting to Eclipse / Wi-Fi.

    SUCCESS Note 7: So in short, the regular activity would be something like this:

    Step 1. Connect PC and Wi-Fi via a cable
    Step 2. Start CMD - to go to Windows DOS prompt
    Step 3. Type "w"
    Step 4. Find connected command in the output
    Step 5. Success, remove cable and start using Eclipse
    
    0 讨论(0)
  • 2020-11-22 07:54

    Best and super easy way to do this is:-

    1. Make a batch file :-

    adb devices

    adb tcpip 5555

    adb connect 192.168.9.120:5555 ( Your phone ip xxx.xxx.x.xxx:5555 )

    1. Place this file into your android sdk platform-tool folder. Example:- C:\Users\'user_name'\AppData\Local\Android\Sdk\platform-tools

    2. Right click file > sendto > Desktop(create shortcut )

    3. That's it....

    Now you just need to connect your phone through USB , then open desktop shortcut and disconnect your phone...

    0 讨论(0)
  • 2020-11-22 07:55

    Connect the device via USB and make sure debugging is working. these steps are taken if you already have installed adb and set it's path in environment varialbe

    1. open cmd and type the following
    2. adb tcpip 5555
    3. find the IP address with adb shell ip route
    4. adb connect DEVICE_IP_ADDRESS:5555
    5. Disconnect USB and proceed with wireless debugging.
    0 讨论(0)
  • 2020-11-22 07:56

    With new Android 11 you can debug your apps over WiFi without using an USB cable at all.

    Quoting from Android Studio User Guide

    Connect to a device over Wi-Fi (Android 11+)

    Android 11 and higher support deploying and debugging your app wirelessly from your workstation using Android Debug Bridge (adb). For example, you can deploy your debuggable app to multiple remote devices without physically connecting your device via USB. This eliminates the need to deal with common USB connection issues, such as driver installation.

    To use wireless debugging, you need to pair your device to your workstation using a pairing code. Your workstation and device must be connected to the same wireless network. To connect to your device, follow these steps:

    1. On your workstation, update to the latest version of the SDK Platform-Tools.
    2. On the device, enable developer options.
    3. Enable the Wireless debugging option.
    4. On the dialog that asks Allow wireless debugging on this network?, click Allow.
    5. Select Pair device with pairing code. Take note of the pairing code, IP address, and port number displayed on the device (see image).
    6. On your workstation, open a terminal and navigate to android_sdk/platform-tools.
    7. Run adb pair ipaddr:port. Use the IP address and port number from step 5.
    8. When prompted, enter the pairing code that you received in step 5. A message indicates that your device has been successfully paired.
        none
        Enter pairing code: 482924
        Successfully paired to 192.168.1.130:37099 [guid=adb-235XY] 
    
    1. (For Linux or Microsoft Windows only) Run adb connect ipaddr:port. Use the IP address and port under Wireless debugging.
    0 讨论(0)
  • 2020-11-22 07:57
    first you shold connect your device with usb to pc after that run cmd and drag and drop adb.exe that is in sdk/platform-tools path and write below code :
    
        ....\Sdk\platform-tools\adb.exe devices
    
        .....\Sdk\platform-tools\adb.exe tcpip 5555
    
        .....\Sdk\platform-tools\adb.exe connect Ip address:5555
    
    0 讨论(0)
  • 2020-11-22 07:58

    See forum post Any way to view Android screen remotely without root? - Post #9.

    1. Connect the device via USB and make sure debugging is working;
    2. adb tcpip 5555. This makes the device to start listening for connections on port 5555;
    3. Look up the device IP address with adb shell netcfg or adb shell ifconfig with 6.0 and higher;
    4. You can disconnect the USB now;
    5. adb connect <DEVICE_IP_ADDRESS>:5555. This connects to the server we set up on the device on step 2;
    6. 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 find the IP address while using OSX run the command adb shell ip route.


    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:

    1. Enable ADB over network in developer setting It should show the IP address
    2. adb connect <DEVICE_IP_ADDRESS>:5555
    3. Disable the setting when done

    Using Android Studio there is a plugin allowing you to connect USB Debugging without the need of using any ADB command from a terminal.

    0 讨论(0)
提交回复
热议问题