0

When running uiautomatorviewer, I am getting the following NullPointerException error:

Enter image description here

I have installed and set up Appium following the setup process and set up environment variables for ANDROID_HOME and the Android SDK. The uiautomatorviewer command is using a Path user variable that points to the directory Sdk/tools/bin, where the uiautomatorviewer.bat file is located. From everything I've read online, running this executable should open up the UiAutomatorViewer application, so I can inspect elements on my Android app. Why isn't this working?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Jeremy Hadfield
  • 189
  • 2
  • 15
  • Please review *[Why not upload images of code/errors when asking a question?](https://meta.stackoverflow.com/questions/285551/)* (e.g., *"Images should only be used to illustrate problems that* ***can't be made clear in any other way,*** *such as to provide screenshots of a user interface."*) and take the appropriate [action](https://stackoverflow.com/posts/54523635/edit). Thanks in advance. – Peter Mortensen Aug 11 '22 at 11:48

4 Answers4

3

The correct fix for this issue:

Java SDKs 9 and 10 do not work with Appium and the Android SDK. You have to uninstall the Java SDK for the more recent version and install the Java 8 SDK instead.

For Linux

Follow this process:

  1. brew cask uninstall java # uninstall java9
  2. brew tap caskroom/versions
  3. brew cask install java8 # install java8
  4. touch ~/.android/repositories.cfg # without this file, error will occur on next step
  5. brew cask install android-sdk

For Windows

  1. Open Add or Remove Programs menu and uninstall Java 9/10.
  2. Install Java 8 using the installer.
Jeremy Hadfield
  • 189
  • 2
  • 15
1

Can you just reconnect the device and restart it and the uiautomator? But make sure the test script is not running in the background. Or you can kill the adb server and restart it again.

You can go and check if you forgot any steps in UIAutomatorViewer Tutorial: Inspector for Android Testing.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
akshay patil
  • 670
  • 7
  • 20
1

I was using uiautomatorviewer with corretto-11.0.13 (after some edits in a .bat file) until I upgraded Android Studio to 2021.2.1 (Chipmunk) (to solve another issue in the Android build) and the problem didn't disappear. Moreover, more problems appeared. uiautomatorviewer didn't work again.

I rolled back to Android Studio 4.1.1, restored a change done in the find_java.bat file, and it worked again.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Erwin
  • 21
  • 2
-1

You must add the following Android/sdk/tools/bin/ in the system environment variable. If you are using window os, you can do it like following:

  1. Right-click on ‘This PC’ and select Properties.
  2. Click 'Advanced system settings' and select ‘Environmental Variables’ option
  3. Under the 'System variables", select 'Path' and click 'Edit'
  4. Click 'New" and add the path of Android/sdk/tools/bin/ in the like

    C:\Users\\AppData\Local\Android\Sdk\tools\bin

then you will be able to run uiautomatorviewer command in the command prompt.

The alternative way is to open command prompt in Android/sdk/tools/bin/ folder and then run uiautomatorviewer command.

Suban Dhyako
  • 2,436
  • 4
  • 16
  • 38
  • 1
    Did you read the question? I stated in my question that I've already set up the environment variables for the Android SDK. Also, you can see in my screenshot that I ran the `uiautomator` command and it had an error output. If I hadn't set up the environment variable correctly, it would have just been a "command not found" error. Pay attention to the question – Jeremy Hadfield Feb 05 '19 at 17:50