# MEmu Play ADB Connect and Port Setup for MAS

> Connect MEmu Play to Macro Automation Studio over ADB on port 21503, add it as a device, fix offline errors, and run MAS macros instead of the recorder.

Source: https://automationmacro.com/docs/memu-setup-guide (Devices, updated 2026-09-04)

This guide shows how to connect MEmu Play to Macro Automation Studio (MAS) over ADB, and how MAS macros differ from the MEmu macro recorder. MEmu ships for Windows only, so every step below is a Windows step.

## Before you start

- MAS installed and signed in on Windows 10 or 11. MAS is a free download for the trial; get it from the [download page](/download).
- MEmu installed from [memuplay.com](https://www.memuplay.com/) and started once.
- The instance fully booted to the Android home screen.
- Virtualization enabled in the BIOS for a stable instance.

## 1. Install MEmu

1. Download MEmu from the vendor site and run the installer.
2. Start MEmu and wait for the home screen.
3. Sign in to the apps you want to automate before you add the device to MAS.

## 2. Set a fixed resolution

MAS matches template images pixel for pixel. Open the MEmu settings, choose a fixed resolution, and keep it. Macros written against the MAS baseline expect **540x960** in portrait at **240 DPI**; a macro you write yourself expects the resolution you captured in Asset Lab. Restart the instance if MEmu asks.

> [!WARNING]
> Changing the resolution after you capture templates moves every match. Pick a resolution once and keep it.

## 3. Enable ADB in MEmu

The official MEmu documentation shows no ADB toggle. A running instance forwards its Android adb port to the host as `127.0.0.1:21503`, which is the address MEmu's own command line guide uses. If your MEmu build has an ADB or developer option under Settings, leave it on. Start the instance and wait for the home screen before you continue.

## 4. The MEmu ADB port and how MAS scans it

MEmu's default instance listens on **21503**. MAS does not use `adb devices` to discover emulators. It scans running processes and keeps ports that match these rules:

- The process name contains `memuheadless` or `memuhyper`.
- The port is 21503 or higher, ends in 3, and is below 30000. Ports such as 21513 and 21523 therefore match as well.
- The socket listens on `127.0.0.1`.

Matching ports appear in the Add Device dialog labelled `MEmu`, for example `21503 - MEmu`. The scan runs when you open a device group and each time you click **Refresh**.

## 5. Connect MEmu Play over ADB in MAS

1. Open **Device Groups** in the sidebar and open a group, or create one.
2. Click **Add Device**.
3. Type a **Device Name** of up to 50 characters.
4. In **Port**, pick the `MEmu` entry for this instance. Click **Refresh** if the list is empty.
5. If MEmu uses a port that does not fit the rule above, choose **Custom Port** and type it. MAS accepts 1024 to 65535.
6. Optionally choose a **Startup Macro**.
7. Click **Add Device**, then click **Start** on the device card.

The card shows **Connecting** and then **Running**. MAS starts its adb server, removes any stale entry for `127.0.0.1:<port>`, and runs `adb connect` against it.

## Macros on MEmu

MEmu's macro recorder captures taps and swipes at fixed coordinates and replays them, optionally on repeat. It does not look at the screen, so a slow load, a pop-up or a moved button breaks the sequence, and the routine only works inside MEmu.

A MAS macro is a Python script that checks the screen before it acts. It finds a button with template matching, reads text with OCR, waits with retries, and branches on what it sees. The same script runs on MEmu, on other emulators and on a cloud device without edits, because MAS drives the device over adb.

- To rebuild a recorded routine as a screen-aware macro, follow [Image recognition macros](/docs/guides/image-recognition-macros).
- To loop it until a condition is met, or run it on a schedule, read [Loops, stop conditions and scheduling](/docs/guides/loops-and-scheduling).
- Marketplace macros install as MAS macros and run on the device you assign.

> [!NOTE]
> Stop the MEmu recorder before you start a device in MAS. Both send input to the same screen and will interfere with each other.

## Several MEmu instances

Each instance from the MEmu multi-instance manager listens on its own port. Add each one as a separate device in the same device group, assign a macro and settings profile per device, and use **Start All** and **Stop All** on the group. See [Device groups](/docs/device-groups) for per-device arguments and proxies.

## Troubleshooting

### MEmu ADB connect

The device card shows **Error** or "Failed to start device", or MAS lists no `MEmu` entry. Work through these causes:

- The instance is still booting. Wait for the home screen, then click **Refresh** and start again.
- The port does not fit the scan rule, so MAS skipped it. Use **Custom Port** with the number MEmu uses.
- The port belongs to a different instance. Fix it with **Edit Device** on the card.
- The scan reported "Failed to scan emulator ports". Restart MAS and open the dialog again.
- adb printed "connection refused" or "cannot connect" in the device logs. Nothing is listening on that port; restart the instance and check the number again.

### MEmu ADB device offline

adb marks a device `offline` when the adb daemon inside the instance stops answering, which often follows a sleep, an update or a second adb server on the machine. Click **Stop** on the card, restart the MEmu instance, close any other tool that runs its own adb server, and click **Start**. MAS disconnects the stale entry and reconnects on every start. If it stays offline, restart MAS so its adb server starts clean.

### MEmu macro recorder versus MAS

A routine recorded in MEmu cannot be imported into MAS, because MAS runs Python macros only. Recreate it: capture the buttons as templates in Asset Lab, click them with `find_object_retry`, and loop with a stop condition. The result survives pop-ups, slow loads and layout changes that break a recorded sequence, and it runs on any device MAS controls. If a MAS macro stalls, open **Logs** on the device card: `ImageNotFoundError` and `TimeoutError` name the step that failed.

## Control it from Python

With the card at **Running**, a macro's `src/app.py` drives the instance through the `mas` package. The port is chosen by MAS, so scripts never reference it.

```python
import mas

size = mas.get_screen_size()
mas.log(f"MEmu screen is {size.width}x{size.height}")

match = mas.find_object_retry(1234, total_tries=3, time_sleep=2.0)
if match:
    mas.click(match.x, match.y)
```

Read the [SDK overview](/docs/sdk) for every namespace, and [Control an Android emulator from Python](/docs/guides/control-an-emulator-from-python) for a complete first script.
