解决MacBook M1下无法运行uiautomatorviewer
Contents
MacBook使用ARM芯片后虽然带来了性能和续航的提升,但是也带来了不少兼容性问题,好在发布几个月后主流的开发工具都慢慢适配完毕,然而一些小众的工具迟迟无法引来更新。所以Rosetta 2
模式仍然非常重要。
默认情况下,我们执行./uiautomatorviewer
会报错:
SWT folder '/Users/xxx/Library/Android/sdk/tools/lib/aarch64' does not exist.
Please export ANDROID_SWT to point to the folder containing swt.jar for your platform.
意思是lib
下没有aarch64
这个目录。
尝试方案1:
在lib
下建立aarch64
目录,网上找aarch64
版本的swt.jar
,无果。
最终报错如下:
Exception in thread "main" java.lang.UnsatisfiedLinkError: Could not load SWT library. Reasons:
no swt-cocoa-4936r26 in java.library.path
no swt-cocoa in java.library.path
Can't load library: /Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa-4936r26.jnilib
Can't load library: /Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa.jnilib
/Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa-4936r26.jnilib: dlopen(/Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa-4936r26.jnilib, 1): no suitable image found. Did find:
/Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa-4936r26.jnilib: mach-o, but wrong architecture
/Users/xxx/.swt/lib/macosx/aarch64/libswt-cocoa-4936r26.jnilib: mach-o, but wrong architecture
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:338)
at org.eclipse.swt.internal.Library.loadLibrary(Library.java:257)
at org.eclipse.swt.internal.C.<clinit>(C.java:19)
at org.eclipse.swt.internal.cocoa.NSMutableArray.arrayWithCapacity(NSMutableArray.java:39)
at org.eclipse.swt.widgets.Canvas.<clinit>(Canvas.java:55)
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)
折腾许久也没找到解决方案,放弃。
尝试方案2:
既然增加aarch64
支持的方案无法解决,那就只能尝试Rosetta 2
方式了。
运行arch -x86_64 ./uiautomatorviewer
无效果。
uiautomatorviewer
依赖Java环境
,我使用的是zulu arm版本jdk
,所以切换jdk
为x64版本。
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_281.jdk/Contents/Home
然后再次执行./uiautomatorviewer
,成功运行。