我无法在我的 macbook M1 上 运行 uiautomatorviewer

I cannot run uiautomatorviewer on my macbook M1

机器
macBook Air M1

OS
macOS 大苏尔版本 11.5.2

java-版本

java版本“1.8.0_301”

Java(TM) SE 运行环境(build 1.8.0_301-b09)

Java HotSpot(TM) 64 位服务器 VM(内部版本 25.301-b09,混合模式)

bash_profile

   export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_301.jdk/Contents/Home
   export PATH=$PATH:$JAVA_HOME/bin
   export PATH=$PATH:$JAVA_HOME/lib
   export MAVEN_HOME=/Users/XXX/Documents/apache-maven-3.8.2
   export M2=$MAVEN_HOME/bin
   export ANDROID_HOME=/Users/XXX/Library/Android/sdk
   export PATH=$PATH:/usr/local/git/bin:/usr/local/bin:
   export PATH=$PATH:$ANDROID_HOME/platform-tools
   export PATH=$PATH:$ANDROID_HOME/tools
   export PATH=$PATH:$ANDROID_HOME/tools/bin
   export PATH=$PATH:$ANDROID_HOME/emulator
   export PATH=$PATH:$ANDROID_HOME/build-tools
   export PATH=$PATH:$ANDROID_HOME/tools/lib/x86_64

在 运行 终端上的 uiautomatorviewer 上我得到以下异常

java.lang.NullPointerException
at org.eclipse.swt.widgets.Control.internal_new_GC(Unknown Source)
at org.eclipse.swt.graphics.GC.<init>(Unknown Source)
at org.eclipse.swt.graphics.GC.<init>(Unknown Source)
at org.eclipse.swt.widgets.Tree.computeSize(Unknown Source)
at org.eclipse.swt.layout.GridData.computeSize(Unknown Source)
at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
at org.eclipse.swt.layout.GridLayout.computeSize(Unknown Source)
at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
at org.eclipse.swt.custom.SashFormLayout.computeSize(Unknown Source)
at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
at org.eclipse.swt.custom.SashFormLayout.computeSize(Unknown Source)
at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
at org.eclipse.swt.layout.FillData.computeSize(Unknown Source)
at org.eclipse.swt.layout.FillLayout.computeChildSize(Unknown Source)
at org.eclipse.swt.layout.FillLayout.computeSize(Unknown Source)
at org.eclipse.swt.widgets.Composite.computeSize(Unknown Source)
at org.eclipse.swt.layout.GridData.computeSize(Unknown Source)
at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
at org.eclipse.swt.layout.GridLayout.layout(Unknown Source)
at org.eclipse.swt.widgets.Composite.updateLayout(Unknown Source)
at org.eclipse.swt.widgets.Composite.updateLayout(Unknown Source)
at org.eclipse.swt.widgets.Composite.layout(Unknown Source)
at org.eclipse.swt.widgets.Display.runSettings(Unknown Source)
at org.eclipse.swt.widgets.Display.readAndDispatch(Unknown Source)
at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)
at org.eclipse.jface.window.Window.open(Window.java:801)
at com.android.uiautomator.UiAutomatorViewer.main(UiAutomatorViewer.java:78)

如果有人遇到过类似的问题并有解决方案,请告诉我。

谢谢, 纳希德

我找到了比 uiautomator 更好的替代品 - appium inspector。

如果您已经在 mac 上安装了 appium GUI,请按照以下步骤操作:

  1. 启动appium服务器
  2. 点击搜索按钮启动appium inspector
  3. 在下方提供您的 android 配置 {
    “平台名称”:“Android”,
    “平台版本”:“8.1”,//<>
    "app": "/path/to/.apk/file", "deviceName": "c33143r", //<>
    “automationName”:“UiAutomator2”
    }

我有以下配置,Java 版本是 1.8。0_332

export ANDROID_SDK=$HOME/Library/Android/sdk
export PATH=$ANDROID_SDK/emulator:$PATH
export PATH=$ANDROID_SDK/tools:$PATH
export PATH=$ANDROID_SDK/tools/bin:$PATH
export PATH=$ANDROID_SDK/platform-tools:$PATH
export ANDROID_SDK_ROOT=$ANDROID_SDK 
export ANDROID_AVD_HOME=$HOME/.android/and
alias emulator='$ANDROID_SDK/emulator/emulator'

就我而言,以下解决方案非常有效

https://github.com/android/android-test/issues/911#issuecomment-849389068

  1. https://download.eclipse.org/eclipse/downloads/index.html 下载 swt.jar,将下载的 swt.jar 重命名为 swt2.jar
  2. 复制swt2.jarLibrary/Android/sdk/tools/lib/x86_64/【注: 不要 REPLACE/DELETE]
  3. 启动 uiautomatorviewer