'adb over Wi-Fi (Android 11+) on Windows: how to keep a fixed port or connect automatically?
The wireless adb connection works fine on my Android 11 phone + Windows workstation.
But it's not convenient, as every time the phone Wifi disconnects/reconnects, I have to:
- Turn on wireless debugging in Android settings.
- Take note of the port number XXXXX, which changes every time!
- Run
adb connect 192.168.1.10:XXXXXon the computer.
Is there a way to skip step 2, by either:
- making the port fixed?
- making Windows automatically detect the phone on the new port? (documentation seems to imply that step 2 and 3 are not needed on MacOS, once the pairing is done, I wonder how this works)
Solution 1:[1]
You can make the port fixed until reboot by adb tcpip
After pairing and connecting with the dynamic port
try adb tcpip 5555
then you can use
adb connect ip:5555 until reboot (ya after reboot you've to connect with dynamic port and set tcpip to 5555 again)
Solution 2:[2]
You can dynamically get port using nmap and connect to it.
here is my solution
adb connect <device_ip>:$(nmap $IP -p 37000-44000 | awk "/\/tcp/" | cut -d/ -f1)
Scanning only ports 37000-44000 is sufficient Also wireless debugging should be enabled and device needs to unlocked during nmap scan. Run it again if the nmap doesn't find the port first time.
I have added the command to an alias so it is easy to run
ex:alias adbw='adb connect 192.168.0.7:$(nmap $IP -p 37000-44000 | awk "/\/tcp/" | cut -d/ -f1)'
To connect next time:
- Unlock Device
- Enable Wireless debugging (you can add it to status bar icons)
- run
adbwif alias set.
Ex Output:connected to 192.168.0.7:38395
Solution 3:[3]
Try importing it like this
import gql from 'graphql-tag';
Basically remove {} wrap
Solution 4:[4]
I think you need to move the mapping through the user into the return statement. Or at if (data) before the return. Seems like the users prop data on is being read before the response has been received.
Solution 5:[5]
import React from "react";
import { useQuery } from "react-apollo";
import { gql } from "graphql-tag";
const QUERY_ALL_USERS = gql`
query getUsers {
users{
name
role
createdAt
}
}
`;
export const Users = () => {
const { loading, error, data } = useQuery(QUERY_ALL_USERS);
if (loading) return 'Loading...';
if (error) return `Error! ${error.message}`;
function User(){
let users
if(data && data?.user){
users = = data.users.map((u) => {
return (
<li>
{u.name} <strong>{u.role}</strong>
</li>
)
})
}
return users
}
return (
<ul>
{!loading && <User/> }
</ul>
);
};
see full code
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
It said Object is not a function, in react, you can't use an object as a component, it has to be a function. Instead of doing
<ul>{ users }</ul>, try to create a function User, return the map array through the function
Function User(){
let user
if(data && data?.users){
users = data.users.map((u) => {
return (
<li>
{u.name} <strong>{u.role}</strong>
</li>
)
})}
return user
}
then changed it to
<ul><User /></ul>
let me know if that works.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | |
| Solution 3 | Deniz Karada? |
| Solution 4 | sculs |
| Solution 5 | Peter Csala |
