我正在尝试在docker容器中运行uiautomatorviewer(来自android sdk工具)。但是我在运行docker容器时遇到了错误。
Exception in thread "main" org.eclipse.swt.SWTError: No more handles [gtk_init_check() failed]
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.createDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.getDefault(Unknown Source)
at org.eclipse.swt.widgets.Shell.<init>(Unknown Source)
at org.eclipse.swt.widgets.Shell.<init>(Unknown Source)
at org.eclipse.jface.window.Window.createShell(Window.java:487)
at org.eclipse.jface.window.Window.create(Window.java:430)
at org.eclipse.jface.window.Window.open(Window.java:790)
at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:78)
我尝试与容器共享.Xauthority文件,并使用下面完全相同的命令来运行容器
docker run --privileged -d -p 4723:4723 -v /dev/bus/usb:/dev/bus/usb -v /home/app/build/outputs/apk/debug:/root/tmp -v $HOME/.Xauthority:/root/.Xauthority:rw --env="DISPLAY" --name container-sdk local/sdk:latest
Dockerfile摘录
FROM ubuntu:16.04
WORKDIR /root
***** downloads Android SDK ***
CMD ["sh", "-c", "export DISPLAY=':0.0' & uiautomatorviewer"]
我成功地在docker容器中运行了firefox浏览器,以确保可以在容器中运行GUI应用程序。但是uiautomatorviewer不会像firefox那样启动。而是引发异常。
感谢您的帮助。