# Issue with installing Appium UIAutomator2 on virtual device

**URL:** <https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159>\
**Category:** Issues/Bugs\
**Created:** [July 8, 2021, 12:33am UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159 "2021-07-08T00:33:42Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 12:33am UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/1 "2021-07-08T00:33:42Z")

</div>

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](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?

---

<div class="post-metadata">

**Author:** ![mykola-mokhnach](https://discuss.appium.io/user_avatar/discuss.appium.io/mykola-mokhnach/32/4578_2.png) [@mykola-mokhnach](https://discuss.appium.io/u/mykola-mokhnach)\
**Post date:** [July 8, 2021, 7:04am UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/2 "2021-07-08T07:04:03Z")

</div>

> [@GetZwifty](#):
>
> The JAVA\_HOME location ‘/usr/libexec/java\_home’ must be a valid folder

The JAVA\_HOME environment variable must be set to a proper value

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 4:20pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/3 "2021-07-08T16:20:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 4:34pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/4 "2021-07-08T16:34:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [July 8, 2021, 4:57pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/5 "2021-07-08T16:57:50Z")

</div>

> [@GetZwifty](#):
>
> Now moving on to figuring out how to start already installed app.

→ [Different capabilities for different scenarios - #3 by Aleksei](https://discuss.appium.io/t/different-capabilities-for-different-scenarios/16694/3)

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 5:09pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/6 "2021-07-08T17:09:22Z")

</div>

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](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`

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [July 8, 2021, 5:17pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/7 "2021-07-08T17:17:52Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 5:28pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/8 "2021-07-08T17:28:58Z")

</div>

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}

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [July 8, 2021, 6:49pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/9 "2021-07-08T18:49:01Z")

</div>

> [@GetZwifty](#):
>
> appActivity

replace with “appWaitActivity”

PS “appPackage” remove. no need.

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 7:11pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/10 "2021-07-08T19:11:15Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Aleksei](https://discuss.appium.io/user_avatar/discuss.appium.io/aleksei/32/6267_2.png) [@Aleksei](https://discuss.appium.io/u/Aleksei)\
**Post date:** [July 8, 2021, 7:23pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/11 "2021-07-08T19:23:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![GetZwifty](https://discuss.appium.io/letter_avatar_proxy/v4/letter/g/9de053/32.png) [@GetZwifty](https://discuss.appium.io/u/GetZwifty)\
**Post date:** [July 8, 2021, 7:53pm UTC](https://discuss.appium.io/t/issue-with-installing-appium-uiautomator2-on-virtual-device/34159/12 "2021-07-08T19:53:04Z")

</div>

Yep, if only I had access to apk 🙂

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](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!
