Skip to content

Connect a phone

Wiki: Connecting a Phone


The bot controls your phone over ADB: it reads the screen and taps through it. You can connect the phone with a USB cable, or over Wi-Fi with wireless debugging.

Before you start:

The commands below use the bot's own copy of ADB, through clashroyalebuildabot adb. It downloads ADB first if it isn't there yet. Run from the source code, use uv run python main.py adb instead.


Step 1: Turn On Developer Options

  1. Open Settings > About phone and tap Build number seven times. Enter your PIN if asked.
  2. Developer options now appear in Settings > System > Developer options. The menu's location varies between phones.

Step 2: Connect the Phone

Pick one of the two options.

Option A: USB

  1. In Developer options, turn on USB debugging.
  2. Connect the phone to your computer with a USB cable.
  3. Accept the Allow USB debugging? prompt on the phone. Tick Always allow from this computer so it doesn't ask again.

On Windows, ADB may also need your phone maker's USB driver (see Install OEM USB drivers). Pixel phones use the Google USB Driver.

Option B: Wireless Debugging

The phone and the computer must be on the same Wi-Fi network.

  1. In Developer options, turn on Wireless debugging and accept the prompt.
  2. Pair the computer (only needed once). Tap Wireless debugging, then Pair device with pairing code. The phone shows a six-digit code and an IP address and port. Run:
    clashroyalebuildabot adb pair 192.168.1.20:37099 123456
    
    with the phone's address, port and code. Keep the pairing screen open until it says it's paired.
  3. Connect. Back on the Wireless debugging screen, IP address & Port shows a different port from the pairing one. Connect to it:
    clashroyalebuildabot adb connect 192.168.1.20:41235
    

The connect port changes each time wireless debugging is turned on again or the phone restarts. Pairing is remembered, so when the port changes, only run adb connect again, with the new port.

Connect before you start the bot. If the bot can't reach the device when it starts, it restarts ADB, and that drops wireless connections.


Step 3: Set the Device Serial

  1. List the connected devices:
    clashroyalebuildabot adb devices
    
    A USB phone is listed by its serial, for example 2A031JEGR09881. A wireless one is listed by its address, for example 192.168.1.20:41235. Next to it should be device. If it says unauthorized, accept the prompt on the phone. If it says offline, unplug and reconnect it, or run adb connect again.
  2. In the bot's web UI, open the Settings tab, enter it as the Device Serial and press Save to config.yaml. You can also set it in config.yaml yourself:
    adb:
      device_serial: 192.168.1.20:41235
    

If the configured device isn't found, the bot uses the first device adb devices lists. So with only one device connected, the serial doesn't need to match. With wireless debugging, update it each time the port changes, or the bot may pick another device.


Step 4: Start the Bot

  1. Unlock the phone and open Clash Royale on the lobby.
  2. Start the bot (clashroyalebuildabot) and press start (▶).

The bot reads the screen at 720x1280 and 240 DPI. As it starts, it sets the phone to that, and puts back the phone's own resolution and density when it stops. Changing them makes Clash Royale reload, which takes a few seconds. To skip the reload each time, set them yourself once:

clashroyalebuildabot adb shell wm size 720x1280
clashroyalebuildabot adb shell wm density 240

If the bot stops without closing properly (it crashed, or the connection or power went), the phone stays at 720x1280. To put it back, run:

clashroyalebuildabot adb shell wm size reset
clashroyalebuildabot adb shell wm density reset

Tips

  • Keep the screen on. The bot can't play on a locked screen. Set a long screen timeout in Settings > Display, or turn on Stay awake in Developer options, which keeps the screen on while the phone is charging.
  • Don't use the phone while the bot plays. Your taps and notifications get in the way of its own.
  • Use the bot's ADB only. If you also have another adb installed (from your package manager or Android Studio), don't run it while the bot is running: use clashroyalebuildabot adb instead. Two different versions keep restarting each other's server, which drops the bot's connection (see E011).

Problems

  • The phone isn't listed by adb devices: for USB, try another cable or port (some cables only charge), and on Windows check the USB driver above. For wireless, check both are on the same network and run adb connect again with the port the phone shows now.
  • E006: the bot couldn't find a device. Check adb devices as in Step 3.
  • E008: the bot lost the connection to the phone. Wireless connections drop when the phone sleeps or changes network: reconnect, then restart the bot.
  • E013: the phone runs Android older than 14.

For the other errors, see Troubleshooting.