Android-MCP icon indicating copy to clipboard operation
Android-MCP copied to clipboard

RPCUnknownError -32001 "ApplicationSharedMemory not initialized" on Android 17 (API 37)

Open Asenadurden opened this issue 2 weeks ago • 2 comments

Description

On a device running Android 17 (API 37), connecting fails at startup. The device is found and the on-device uiautomator2 server starts, but the first deviceInfo RPC fails with ApplicationSharedMemory not initialized, so Android-MCP exits before serving any request.

The same error happens with plain uiautomator2, without Android-MCP involved, so this looks like an on-device server incompatibility with Android 17 rather than a connection problem.

Environment

  • Android-MCP: 0.1.0
  • uiautomator2: 3.3.1, then upgraded to 3.7.1 (same error with both)
  • adbutils: 2.9.2, then 2.12.0
  • fastmcp: 2.14.0
  • Host OS: Windows 10.0.26320
  • Device: Samsung SM-A546E, Android 17 (SDK 37)
  • Connection: wireless debugging (paired with adb pair), adb devices shows the device as device
  • Launched with --device <adb-...-._adb-tls-connect._tcp>

Steps to reproduce

  1. Pair and connect an Android 17 device over adb.
  2. Run:
import uiautomator2 as u2
d = u2.connect("<device serial>")
print(d.info)

(Starting android-mcp --device <serial> fails the same way.)

Actual result

uiautomator2.exceptions.RPCUnknownError: ('Unknown RPC error: -32001 java.lang.IllegalStateException', {}, 'java.lang.IllegalStateException: ApplicationSharedMemory not initialized
	at com.android.internal.os.ApplicationSharedMemory.getInstance(ApplicationSharedMemory.java:81)
	at android.view.WindowManagerGlobal.getWindowManagerService(WindowManagerGlobal.java:305)
	at android.window.WindowTokenClientController.attachToDisplayArea(WindowTokenClientController.java:116)
	at android.window.WindowContext.attachToDisplayArea(WindowContext.java:113)
	at android.app.ContextImpl.createWindowContext(ContextImpl.java:3298)
	at androidx.test.uiautomator.UiDevice$Api31Impl.createWindowContext(UiDevice.java:1584)
	at androidx.test.uiautomator.UiDevice.getUiContext(UiDevice.java:1454)
	at androidx.test.uiautomator.UiDevice.getDisplaySizeDp(UiDevice.java:312)
	at com.wetest.uia2.stub.DeviceInfo.<init>(DeviceInfo.java:58)
	at com.wetest.uia2.stub.AutomatorServiceImpl.deviceInfo(AutomatorServiceImpl.java:183)
	...')

Android-MCP then raises: RuntimeError: Unexpected error connecting to device <serial>: ...

Expected result

The connection succeeds and d.info returns device information.

Notes

  • Force-stopping the uiautomator processes on the device and reconnecting did not help.
  • Upgrading uiautomator2 from 3.3.1 to 3.7.1 (which updates the on-device components) did not change the error.
  • I have not tested other Android versions on this exact setup.
  • Is Android 17 support planned? Happy to test a fix or provide more logs (e.g. logcat).

Asenadurden avatar Nov 17 '26 22:11 Asenadurden

  • The same Android-MCP setup (uiautomator2 3.3.1) starts and serves requests normally against an Android 16 (API 36.1) emulator, so this seems specific to Android 17 (API 37), or possibly to physical devices on that version.

Asenadurden avatar Nov 17 '26 22:11 Asenadurden

Thanks for the detailed report. The crash is inside uiautomator2's on-device server (com.wetest.uia2.stub → androidx UiDevice.getDisplaySizeDp), which is why plain uiautomator2 fails too. Android-MCP can't work around it while it depends on that server.

Android-MCP no longer uses uiautomator2 (#39): it talks to the device only through adb shell commands and installs nothing on the device. That rewrite is now released as v0.3.0 on PyPI. Could you try it on your Android 17 phone?

uvx --python 3.13 [email protected] --device <serial>

(or pip install --upgrade android-mcp). It would also help to know whether adb exec-out uiautomator dump /dev/tty and adb exec-out screencap -p > s.png work there.

Jeomon avatar Nov 20 '26 04:11 Jeomon