How to use appium-uiautomator2-driver with webdriver.io

I am using appium-uiautomator2-driver to start a server on an Android device with following code

const {startServer} = require('appium-uiautomator2-driver')
startServer()
const { AndroidUiautomator2Driver } = require("appium-uiautomator2-driver");

const startDriver = async () => {
  const driver = new AndroidUiautomator2Driver();
  const capabilities = {
    automationName: "UiAutomator2",
    platformName: "Android",
    deviceName: "emulator-5554",
  };
  await driver.createSession(capabilities);
};
startDriver().catch((e) => console.error(e));

And then I am trying to connect with webdriver.io to the server running on the device like that:

const wdio = require("webdriverio");

const driverPromise = wdio.attach({
  isAndroid: true,
  port: 8213,
  isMobile: true,
  automationName: 'UiAutomator2',
  sessionId: "56667cc9-625e-4e13-8c4d-354d1928d859",
});

driverPromise.then(async function (driver) {
  await driver.touchAction([
    { action: "press", x: 200, y: 200 },
    { action: "moveTo", x: 200, y: 300 },
    "release",
  ]);
});

But what I get is an UnknownCommandException:

2021-12-09T18:01:20.083Z ERROR webdriver: Request failed with status 404 due to unknown command: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
(node:61813) UnhandledPromiseRejectionWarning: io.appium.uiautomator2.common.exceptions.UnknownCommandException: The requested resource could not be found, or a request was received using an HTTP method that is not supported by the mapped resource
	at io.appium.uiautomator2.http.ServerHandler.channelRead(ServerHandler.java:75)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.CombinedChannelDuplexHandler$DelegatingChannelHandlerContext.fireChannelRead(CombinedChannelDuplexHandler.java:435)
	at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:293)
	at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:267)
	at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:250)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.handler.timeout.IdleStateHandler.channelRead(IdleStateHandler.java:266)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:345)
	at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1294)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:366)
	at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:352)
	at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:911)
	at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
	at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:611)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:552)
	at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:466)
	at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:438)
	at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:140)
	at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144)
	at java.lang.Thread.run(Thread.java:919)

Can anyone tell me what the problem is? Is the UIAutomator driver incompatible with webdriver.io? It should be, because the readme.md says “The driver operates in scope of W3C WebDriver protocol with several custom extensions to cover operating-system specific scenarios.”

I was thinking that maybe the whole appium framework needs to be set up, but I am looking for a light weight and portable solution, so that’s not an option…

Any hints are welcome!

Did you solve the problem, I also have the same problem?