At the time of writing this blog. Some tools (Like uiautomatorviewer) in the Android SDK are not compatible with ARM macOS.

However, the uiautomatorviewer is a Java program. It can be easily “hacked” to run on ARM machines.

Preparations

  1. JRE 8. I chose Zulu-8 (Java 9+ may has more difficulties to work well. I gave up to make it run on openjdk-19)
  2. Eclipse SWT 4.20 for macosx-aarch64

Install SWT

  1. Goto the Android SDK tools directory.

    1
    cd ANDROID_HOME/tools
  2. Create lib/aarch64 directory.

    1
    mkdir lib/aarch64
  3. Copy lib/x86_64/swt.jar to lib/aarch64/swt.jar

    1
    cp lib/x84_64/swt.jar lib/aarch64/swt.jar
  4. Copy SWT 4.20 jar to lib/aarch64/ as swt2.jar

    1
    cp /downloaded/swt/jar/path lib/aarch64/swt2.jar 

Run the uiautomatorviewer

Make sure you are currently running Java 8

1
2
3
4
5
java -version

openjdk version "1.8.0_352"
OpenJDK Runtime Environment (Zulu 8.66.0.15-CA-macos-aarch64) (build 1.8.0_352-b08)
OpenJDK 64-Bit Server VM (Zulu 8.66.0.15-CA-macos-aarch64) (build 25.352-b08, mixed mode)

In ANDROID_HOME/tools, run the command:

1
bin/uiautomatorviewer

Java 9+ ?

Since Java 9, -Djava.ext.dirs parameter was unsupported.
You should try to use -classpath instead.

-classpath is useless when using -jar.
To add external classes when running a jar, should use -Xbootclasspath/a: instead.

Example

1
java -Xbootclasspath/a:"lib/aarch64/swt2.jar:lib/aarch64/swt.jar:lib/others.jar" -XstartOnFirstThread -jar lib/uiautomatorviewer-26.0.0-dev.jar

I’ve tried this, but ran into some other issues.

Reference