Issue with installing Appium UIAutomator2 on virtual device

Having troubles with getting UIAutomator2 setup on a virtual Android device.

Running this on Mac desktop: Appium v1.20.2

These are the steps I followed to setup Appium: https://krishnachetan.medium.com/setup-appium-on-mac-1e06f1178427

I didn’t setup and optional libraries, but all core tools/libraries should be setup. This is also working fine with iOS simulators.

When I run appium-doctor, I don’t get any errors what so ever.

Everything seems to be going fine until I hit these steps:

[ADB] 'io.appium.uiautomator2.server' is not installed

[ADB] App '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.17.4.apk' is not installed

[UiAutomator2] io.appium.uiautomator2.server installation state: notInstalled

[ADB] Checking app cert for /Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.17.4.apk

[ADB] Using 'apksigner.jar' from '/Users/vd/Library/Android/sdk/build-tools/31.0.0-rc5/lib/apksigner.jar'

[UiAutomator2] Deleting UiAutomator2 session

[UiAutomator2] Deleting UiAutomator2 server session

[WD Proxy] Matched '/' to command name 'deleteSession'

[UiAutomator2] Did not get confirmation UiAutomator2 deleteSession worked; Error was: UnknownError: An unknown server-side error occurred while processing the command. Original error: Trying to proxy a session command without session id

[ADB] Running '/Users/vd/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell am force-stop com.zwift.android.alpha'

[Logcat] Stopping logcat capture

[ADB] Removing forwarded port socket connection: 8200

[ADB] Running '/Users/vd/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 forward --remove tcp:8200'

[UiAutomator2] Restoring hidden api policy to the device default configuration

[ADB] Running '/Users/vd/Library/Android/sdk/platform-tools/adb -P 5037 -s emulator-5554 shell 'settings delete global hidden_api_policy_pre_p_apps;settings delete global hidden_api_policy_p_apps;settings delete global hidden_api_policy''

[BaseDriver] Event 'newSessionStarted' logged at 1625703419935 (17:16:59 GMT-0700 (Pacific Daylight Time))

[MJSONWP] Encountered internal error running command: Error: Cannot verify the signature of '/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-uiautomator2-server/apks/appium-uiautomator2-server-v4.17.4.apk'. Original error: The JAVA_HOME location '/usr/libexec/java_home' must be a valid folder

[MJSONWP] at ADB.checkApkCert (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/apk-signing.js:270:11)

I’m not sure what else I can do to resolve this issue. Has anyone run into anything similar?

The JAVA_HOME environment variable must be set to a proper value

1 Like

Yep, I’ve double and triple checked that.

It’s currently set to:
export JAVA_HOME=$(/usr/libexec/java_home)

When I run echo on JAVA_HOME, I get: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home

I’ve tried to setup JDK8 and JDK16, as I’m using Android SDK 30.X, and these tools might require JDK9+

Appium doctor also shows that JAVA_HOME is set correctly.

I just don’t know what else I can try at this point.

OMG, I just realized that desktop app has its own set of paths to ANDROID and JAVA HOME.

It was set to: /usr/libexec/java_home

Setting it to: /Library/Java/JavaVirtualMachines/adoptopenjdk-8.jdk/Contents/Home - fixed the problem.

Now moving on to figuring out how to start already installed app.

Different capabilities for different scenarios - #3 by Aleksei

Thanks for the link, I’m trying to figure out my apps activity name right now. I’m getting ‘java.lang.SecurityException: Permission Denial’ error with my current setup.

This article is also helping: https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md

My biggest challenge now is to figure out how app activity is supposed to be set. This is my latest error:
cmp=com.myapp.android.alpha/com.myapp.android.ui.activity.MainActivity } from null (pid=19268, uid=2000) not exported from uid 10154

just set it to “*”. Appium will find itself.
see: For example com.mycomany.* will match any of com.mycomany.foo , com.mycomany.bar .

Hmm, so these are my full caps:

{
  "platformName": "Android",
  "deviceName": "emulator-5554",
  "platformVersion": "11.0",
  "orientation": "PORTRAIT",
  "automationName": "UiAutomator2",
  "appPackage": "com.myapp.android.alpha",
  "noReset": true,
  "newCommandTimeout": 0,
  "appActivity": "com.myapp.*"
}

And this is the error I’m seeing:
Encountered internal error running command: Error: Cannot start the 'com.myapp.android.alpha' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Cannot start the 'com.myapp.android.alpha' application. Visit https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/android/activity-startup.md for troubleshooting. Original error: Activity name '.com.myapp.*' used to start the app doesn't exist or cannot be launched! Make sure it exists and is a launchable activity

When I ran ‘adb shell dumpsys window windows’ command, I saw these activities related to my app:
mActivityRecord=ActivityRecord{ca9905d u0 com.myapp.android.alpha/com.myapp.android.ui.activity.MainActivity t30}

replace with “appWaitActivity”

PS “appPackage” remove. no need.

Thanks for continuing support! Really appreciate it.

No need for ‘appPackage’ var? How would the app be called to start then?

I’ve tried to use these caps:

{
  "platformName": "Android",
  "deviceName": "emulator-5554",
  "platformVersion": "11.0",
  "orientation": "PORTRAIT",
  "automationName": "UiAutomator2",
  "noReset": true,
  "newCommandTimeout": 0,
  "appWaitActivity": "com.myapp.*"
}

This did connect me to my emulator, but this didn’t start my app though. At this point I don’t think I need appWaitActicity either, since it just connects uiautomator2 server to the emulator.

Aaa you do not provide app as ‘apk’ file. Then you need. Better switch to apk file under test and give path to it in capabilities.

Yep, if only I had access to apk :slight_smile:

I have to get to already installed app on the device.

Okay, figured it out by following steps listed on this site: https://sqa.stackexchange.com/questions/12897/how-to-do-a-testing-on-an-already-installed-android-application-using-appium-s

These are the caps that allowed me to start my app:

{
  "platformName": "Android",
  "deviceName": "emulator-5554",
  "platformVersion": "11.0",
  "orientation": "PORTRAIT",
  "automationName": "UiAutomator2",
  "noReset": true,
  "newCommandTimeout": 0,
  "appPackage": "com.myapp.android.alpha",
  "appActivity": "com.myapp.android.ui.activity.LoginActivity"
} 

Finally made it!