Search code examples
appium

Can't start a session for Appium Inspector - Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported


I am using Appium V2.0 and for Appium Inspector client I am getting the following:

enter image description here

My ENV variables have been set up in Windows 10 accordingly:

enter image description here

Path for both system and user variables are:

C:\Users\slai6\AppData\Local\Android\Sdk\platform-tools C:\Users\slai6\AppData\Local\Android\Sdk\emulator C:\Users\slai6\AppData\Local\Android\Sdk\tools\bin

Server log :

C:\Users\slai6>appium server -p 9000 -a 127.0.0.1
[Appium] Welcome to Appium v2.0.0-beta.55
[Appium] Non-default server args:
[Appium] {
[Appium]   address: '127.0.0.1',
[Appium]   port: 9000
[Appium] }
[Appium] Attempting to load driver uiautomator2...
[debug] [Appium] Requiring driver at C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver
[Appium] Appium REST http interface listener started on 127.0.0.1:9000
[Appium] Available drivers:
[Appium]   - [email protected] (automationName 'UiAutomator2')
[Appium] No plugins have been installed. Use the "appium plugin" command to install the one(s) you want to use.


[HTTP] --> POST /session
[HTTP] {"capabilities":{"alwaysMatch":{"appium:platformName":"Android","appium:automationName":"UIAutomator2","appium:deviceName":"PixelSix","appium:app":"C:\\Users\\slai6\\Downloads\\ReactNativePipeline20230207.1.apk","appium:platformVersion":"11","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]},"desiredCapabilities":{"appium:platformName":"Android","appium:automationName":"UIAutomator2","appium:deviceName":"PixelSix","appium:app":"C:\\Users\\slai6\\Downloads\\ReactNativePipeline20230207.1.apk","appium:platformVersion":"11","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true}}
[debug] [AppiumDriver@3ea3] Calling AppiumDriver.createSession() with args: [{"appium:platformName":"Android","appium:automationName":"UIAutomator2","appium:deviceName":"PixelSix","appium:app":"C:\\Users\\slai6\\Downloads\\ReactNativePipeline20230207.1.apk","appium:platformVersion":"11","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},null,{"alwaysMatch":{"appium:platformName":"Android","appium:automationName":"UIAutomator2","appium:deviceName":"PixelSix","appium:app":"C:\\Users\\slai6\\Downloads\\ReactNativePipeline20230207.1.apk","appium:platformVersion":"11","appium:newCommandTimeout":3600,"appium:connectHardwareKeyboard":true},"firstMatch":[{}]}]
[debug] [AppiumDriver@3ea3] Event 'newSessionRequested' logged at 1676346925975 (14:55:25 GMT+1100 (Australian Eastern Daylight Time))
[BaseDriver] The capabilities ["platformName"] are standard capabilities and do not require "appium:" prefix
[Appium] Attempting to find matching driver for automationName 'UIAutomator2' and platformName 'Android'
[Appium] The 'uiautomator2' driver was installed and matched caps.
[Appium] Will require it at C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver
[debug] [Appium] Requiring driver at C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver
[AppiumDriver@3ea3] Appium v2.0.0-beta.55 creating new AndroidUiautomator2Driver (v2.12.3) session
[AppiumDriver@3ea3] Checking BaseDriver versions for Appium and AndroidUiautomator2Driver
[AppiumDriver@3ea3] Appium's BaseDriver version is 9.3.1
[AppiumDriver@3ea3] AndroidUiautomator2Driver's BaseDriver version is 9.3.1
[debug] [AndroidUiautomator2Driver@a95b] Creating session with W3C capabilities: {
[debug] [AndroidUiautomator2Driver@a95b]   "alwaysMatch": {
[debug] [AndroidUiautomator2Driver@a95b]     "platformName": "Android",
[debug] [AndroidUiautomator2Driver@a95b]     "appium:automationName": "UIAutomator2",
[debug] [AndroidUiautomator2Driver@a95b]     "appium:deviceName": "PixelSix",
[debug] [AndroidUiautomator2Driver@a95b]     "appium:app": "C:\\Users\\slai6\\Downloads\\ReactNativePipeline20230207.1.apk",
[debug] [AndroidUiautomator2Driver@a95b]     "appium:platformVersion": "11",
[debug] [AndroidUiautomator2Driver@a95b]     "appium:newCommandTimeout": 3600,
[debug] [AndroidUiautomator2Driver@a95b]     "appium:connectHardwareKeyboard": true
[debug] [AndroidUiautomator2Driver@a95b]   },
[debug] [AndroidUiautomator2Driver@a95b]   "firstMatch": [
[debug] [AndroidUiautomator2Driver@a95b]     {}
[debug] [AndroidUiautomator2Driver@a95b]   ]
[debug] [AndroidUiautomator2Driver@a95b] }
[AndroidUiautomator2Driver@a95b] The following capabilities were provided, but are not recognized by Appium:
[AndroidUiautomator2Driver@a95b]   connectHardwareKeyboard
[AndroidUiautomator2Driver@a95b (b8865142)] Session created with session id: b8865142-7c11-4a95-bbb4-62e26355f955
[BaseDriver] Using local app 'C:\Users\slai6\Downloads\ReactNativePipeline20230207.1.apk'
[debug] [AndroidUiautomator2Driver@a95b (b8865142)] Checking whether app is actually present
[debug] [AndroidUiautomator2Driver@a95b (b8865142)] Deleting UiAutomator2 session
[debug] [AppiumDriver@3ea3] Event 'newSessionStarted' logged at 1676346926130 (14:55:26 GMT+1100 (Australian Eastern Daylight Time))
[debug] [AppiumDriver@3ea3] Encountered internal error running command: Error: Neither ANDROID_HOME nor ANDROID_SDK_ROOT environment variable was exported. Read https://developer.android.com/studio/command-line/variables for more details
[debug] [AppiumDriver@3ea3]     at requireSdkRoot (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-adb\lib\helpers.js:81:11)
[debug] [AppiumDriver@3ea3]     at Function.createADB (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-adb\lib\adb.js:80:37)
[debug] [AppiumDriver@3ea3]     at Object.createBaseADB (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-android-driver\lib\android-helpers.js:129:20)
[debug] [AppiumDriver@3ea3]     at Object.getDeviceInfoFromCaps (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\node_modules\appium-android-driver\lib\android-helpers.js:220:29)
[debug] [AppiumDriver@3ea3]     at AndroidUiautomator2Driver.startUiAutomator2Session (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:350:40)
[debug] [AppiumDriver@3ea3]     at AndroidUiautomator2Driver.createSession (C:\Users\slai6\.appium\node_modules\appium-uiautomator2-driver\lib\driver.js:241:18)
[debug] [AppiumDriver@3ea3]     at AppiumDriver.createSession (C:\Users\slai6\AppData\Roaming\npm\node_modules\appium\lib\appium.js:337:35)
[HTTP] <-- POST /session 500 246 ms - 882

I've also used Appium doctor to troublkeshoot the set up issues and this is what it said:

info AppiumDoctor Appium Doctor v.2.0.7
info AppiumDoctor ### Diagnostic for necessary dependencies starting ###
info AppiumDoctor  ✔ APPIUM_HOME is C:\Users\slai6\.appium
info AppiumDoctor  ✔ The Node.js binary was found at: C:\Program Files\nodejs\node.EXE
info AppiumDoctor  ✔ Node version is 19.6.0
WARN AppiumDoctor  ✖ ANDROID_HOME environment variable is NOT set!
info AppiumDoctor  ✔ JAVA_HOME is set to: C:\Program Files\Java\jdk-19
WARN AppiumDoctor  ✖ adb, emulator, apkanalyzer.bat could not be found because ANDROID_HOME or ANDROID_SDK_ROOT is NOT set!
info AppiumDoctor  ✔ 'bin' subfolder exists under 'C:\Program Files\Java\jdk-19'
info AppiumDoctor ### Diagnostic for necessary dependencies completed, 2 fixes needed. ###
info AppiumDoctor
info AppiumDoctor ### Diagnostic for optional dependencies starting ###
WARN AppiumDoctor  ✖ ffmpeg cannot be found
WARN AppiumDoctor  ✖ mjpeg-consumer cannot be found.
WARN AppiumDoctor  ✖ bundletool.jar cannot be found
WARN AppiumDoctor  ✖ gst-launch-1.0.exe and/or gst-inspect-1.0.exe cannot be found
info AppiumDoctor ### Diagnostic for optional dependencies completed, 4 fixes possible. ###
info AppiumDoctor
info AppiumDoctor ### Manual Fixes Needed ###
info AppiumDoctor The configuration cannot be automatically fixed, please do the following first:
WARN AppiumDoctor  ➜ Make sure the environment variable ANDROID_HOME is properly configured for the Appium process. Refer https://github.com/appium/java-client/blob/master/docs/environment.md for more details.
WARN AppiumDoctor  ➜ Manually configure ANDROID_HOME and run appium-doctor again.
info AppiumDoctor
info AppiumDoctor ### Optional Manual Fixes ###
info AppiumDoctor The configuration can install optionally. Please do the following manually:
WARN AppiumDoctor  ➜ ffmpeg is needed to record screen features. Please read https://www.ffmpeg.org/ to install it
WARN AppiumDoctor  ➜ mjpeg-consumer module is required to use MJPEG-over-HTTP features. Please install it with 'npm i -g mjpeg-consumer'.
WARN AppiumDoctor  ➜ bundletool.jar is used to handle Android App Bundle. Please read http://appium.io/docs/en/writing-running-appium/android/android-appbundle/ to install it. Also consider adding the ".jar" extension into your PATHEXT environment variable in order to fix the problem for Windows
WARN AppiumDoctor  ➜ gst-launch-1.0.exe and gst-inspect-1.0.exe are used to stream the screen of the device under test. Please read https://appium.io/docs/en/writing-running-appium/android/android-screen-streaming/ to install them and for more details
info AppiumDoctor
info AppiumDoctor ###
info AppiumDoctor
info AppiumDoctor Bye! Run appium-doctor again when all manual fixes have been applied!

I don't know why is says that I haven't set the env variables when I have already done this in Windows.


Solution

  • For some reason after a few server restarts and command prompt close and re-opens I ran the Appium doctor and it said that it could find ANDROID_HOME

    I did add C:\Users\slai6\AppData\Local\Android\Sdk\tools to my Path though.

    Honestly, I am not sure what fixed it but it is working now !