ANDROID_HOME env variable issues

Hey Guys,

Happy new year all, I’d gratefully appreciate if someone could help or shed some light into this issue.

I’ve just set up appium 1.7.2 server on MAC OS High Sierra v 10.13.2, running appium through below command.
appium -a 127.0.0.1 -p 4723 --log-level=debug


Below is my .bash_profile

n.nadarajah@EGHJ-MACRDV01 ~ $ cat ~/.bash_profile
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
ANDROID_HOME=/Users/n.nadarajah/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
ANDROID_PLATFORM_TOOLS=$ANDROID_HOME/platform-tools
ANDROID_TOOLS=$ANDROID_HOME/tools
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}:$JAVA_HOME:$ANDROID_HOME:
$ANDROID_PLATFORM_TOOLS:$ANDROID_TOOLS"
export PATH

Echoing $ANDRIOD_HOME env variable

n.nadarajah@EGHJ-MACRDV01 ~ $ echo $ANDROID_HOME
/Users/n.nadarajah/Library/Android/sdk

Below are the Appium logs on test execution.

n.nadarajah@EGHJ-MACRDV01 ~ $ appium -a 127.0.0.1 -p 4723 --log-level=debug
info: Welcome to Appium v1.4.16 (REV ae6877eff263066b26328d457bd285c0cc62430d)
info: Appium REST http interface listener started on 127.0.0.1:4723
info: [debug] Non-default server args: {"address":"127.0.0.1"}
info: Console LogLevel: debug
info: --> POST /wd/hub/session {"capabilities":{"alwaysMatch":{"platformName":"Android"},"firstMatch":
[{}]},"desiredCapabilities":{"deviceName":"Android Emulator","app":"/Users/n.nadarajah/sites/Resilient-

QA/EndToEndTesting/apks/app-
debug.apk",“platformName”:“Android”,“automationName”:“appium”,“appPackage”:“com.resilientplc.smartnumbers.debug”}}
info: Client User-Agent string: Python http auth
info: [debug] No appActivity desired capability or server param. Parsing from apk.
info: [debug] Using local app from desired caps: /Users/n.nadarajah/sites/Resilient-QA/EndToEndTesting/apks/app-debug.apk
info: [debug] Creating new appium session a5cfbee9-bcd6-41af-a90c-0389ab244d2c
info: Starting android appium
info: [debug] Getting Java version
info: Java version is: 1.8.0_151
info: [debug] Checking whether adb is present
warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
info: [debug] executing cmd: which adb
info: [debug] Using adb from /Users/n.nadarajah/Library/Android/sdk/platform-tools/adb

info: [debug] Parsing package and activity from app manifest
info: [debug] Checking whether aapt is present
warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for aapt.
info: [debug] executing cmd: which aapt
error: Problem parsing package and activity from manifest: Error: Could not find aapt. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
info: [debug] Cleaning up android objects
info: [debug] Cleaning up appium session
error: Failed to start an Appium session, err was: Error: Could not find aapt. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
info: [debug] Error: Could not find aapt. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
    at ADB.<anonymous> (/usr/local/lib/node_modules/appium/node_modules/appium-adb/lib/adb.js:126:12)
    at ChildProcess.exithandler (child_process.js:279:5)
    at ChildProcess.emit (events.js:159:13)
    at maybeClose (internal/child_process.js:943:16)
    at Socket.stream.socket.on (internal/child_process.js:363:11)
    at Socket.emit (events.js:159:13)
    at Pipe._handle.close [as _onclose] (net.js:568:12)
info: [debug] Responding to client with error: {"status":33,"value":{"message":"A new session could not be created. 
(Original error: Could not find aapt. Please set the ANDROID_HOME environment variable with the Android SDK root 

directory path.)",“origValue”:“Could not find aapt. Please set the ANDROID_HOME environment variable with the
Android SDK root directory path.”},“sessionId”:null}
info: <-- POST /wd/hub/session 500 164.317 ms - 344


Questions:

  1. Why does appium cannot see the system environment variable?

I’ve tried appium server versions 1.7.2 & 1.7.1 & 1.6.2 & 1.4.16 the symptoms were the same.
Could someone help me out with this please.

Thanks
Niro

What is the output when you manually run:

which aapt

Hi Telmo,

Thanks for the swift response,
What do you mean by manual run?
You mean it through a native device? if so I haven’t attempted it,
will give it a try and let you know shortly.

Thanks
Niro

You open terminal on your OSX and run that command

Ah I got you now,

which command doesn’t through any results

n.nadarajah@EGHJ-MACRDV01 ~ $ which aapt
n.nadarajah@EGHJ-MACRDV01 ~ $

Should it be though?

Thanks
Niro

It means aapt its not on path or not installed. That’s why Appium fails when trying to look for it.

Ah I see, I think i’m missing something on initial set up Telmo,

Please find the attached Telmo,
As you can see I’ve installed the Android SDK through Android Studio,
Not sure how to go about installing (aapt - Android Asset Packaging tool) separately, I thought the Android SDK studio takes care of this.

Any chance you could shed some light on this, I’m gonna research soon about AAPT and how its missed through Andriod SDK installation.

Any help would be much appreciated.

Thanks
Niroshan

look under folder ANDROID_HOME\build-tools and add it to path

Thanks very much for you swift comments Telmo,
unfortunately that didn’t work either.

Please see below,
command which aapt still doesn’t through any results.

Build toos

n.nadarajah@EGHJ-MACRDV01 ~/Library/Android/sdk/build-tools $ ls
26.0.2	27.0.3

bash_profile

n.nadarajah@EGHJ-MACRDV01~ $ cat ~/.bash_profile
# Setting PATH for Python 2.7
# The original version is saved in .bash_profile.pysave
ANDROID_HOME=/Users/n.nadarajah/Library/Android/sdk
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home/bin
ANDROID_PLATFORM_TOOLS=$ANDROID_HOME/platform-tools
ANDROID_TOOLS=$ANDROID_HOME/tools
ANDROID_BUILD_TOOLS=$ANDROID_HOME/build-tools
PATH="/Library/Frameworks/Python.framework/Versions/2.7/bin:${PATH}:$JAVA_HOME:

$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$ANDROID_TOOLS:
$ANDROID_BUILD_TOOLS"
export PATH


Do you think may be I should reinstall android studio or may be install through command line after removing android studio installations?
I came across this - https://gist.github.com/agrcrobles/165ac477a9ee51198f4a870c723cd441

what would be your advise?

Thanks
Niroshan

when I said look under folder ANDROID_HOME\build-tools, you need to enter one of the sdk versions :slight_smile: just look for the aapt file on your OSX :slight_smile:

As you may have already noticed I’m new to this,
your advise on adding build-tools version did the trick,
I’m pointing v27.0.3

Many thanks again for your help Telmo, I knew I was doing something wrong, hence the reason I didn’t raise this as appium bug.
:slight_smile:

Have a good day.

1 Like

hi telmo im facing same issue everything is set correctly but still can run appium pragmatically
im getting this error

indent preformatted text by 4 spaces    [ADB] The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.    

here is my bash file :

export PATH="/home/linuxbrew/.linuxbrew/bin:$PATH"
export MANPATH="/home/linuxbrew/.linuxbrew/share/man:$MANPATH"
export INFOPATH="/home/linuxbrew/.linuxbrew/share/info:$INFOPATH"

export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
export PATH=$PATH:$JAVA_HOME/bin
export PATH=$PATH:$JAVA_HOME/jre/bin

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools
export PLATFORM_TOOLS="/home/amrka/Android/Sdk/platform-tools"

export NODE_HOME="/usr/local/bin/node"


here is sample of the code
service = AppiumDriverLocalService .buildService(new AppiumServiceBuilder() .usingDriverExecutable(new File("/usr/bin/node")) .withAppiumJS(new File("/home/linuxbrew/.linuxbrew/lib/node_modules/appium/build/lib/main.js")) .withArgument(Arg.ADDRESS,URL_) .withArgument(Arg.PORT,Sport) .withArgument(Arg.CALLBACKPORT,Sport) .withArgument(Arg.WDALOCALPORT,wdaPort) .withArgument(Arg.BootstrapPort,bootStrap) // .withArgument(Arg.NODECONFIG,path) //uncomment this when use parallel test with grid .withArgument(Arg.SESSIONOVERRIDE)); service.start();
same code working fine in windows and ios but not with ubunto

Hi @Telmo_Cardoso ,

I am getting the same error even after setting everything, Please can you check once ?

Here is my nano ~/.profile

export JAVA_HOME=$(/usr/libexec/java_home)
export PATH=$JAVA_HOME/bin:$PATH

export ANDROID_HOME=/Users/krishnakiran/Library/Android/sdk
export PATH=$ANDROID_HOME:$PATH
export PATH=$ANDROID_HOME/platform-tools:$PATH
export PATH=$ANDROID_HOME/tools/bin:$PATH
export PATH=$ANDROID_HOME/build-tools/29.0.0:$PATH

launchctl setenv ANDROID_HOME /Users/krishnakiran/Library/Android/sdk

Heres the which appt on terminal

/Users/krishnakiran/Library/Android/sdk/build-tools/29.0.0/aapt

Here’s the error message

e[35m[Appium]e[39m Welcome to Appium v1.13.0
e[35m[Appium]e[39m Non-default server args:
e[35m[Appium]e[39m address: 127.0.0.1
e[35m[Appium]e[39m fullReset: true
e[35m[Appium]e[39m Deprecated server args:
e[35m[Appium]e[39m e[31m–full-resete[39m => --default-capabilities ‘{“fullReset”:true}’
e[35m[Appium]e[39m Default capabilities, which will be added to each request unless overridden by desired capabilities:
e[35m[Appium]e[39m fullReset: true
e[35m[Appium]e[39m Appium REST http interface listener started on 127.0.0.1:4723
Appium server started.
08 Jul 2019 11:05:07 INFO logger - Appium server started successfully
08 Jul 2019 11:05:07 INFO logger - --------------------------------------
e[35m[HTTP]e[39m e[37m–>e[39m e[37mPOSTe[39m e[37m/wd/hub/sessione[39m
e[35m[HTTP]e[39m e[90m{“desiredCapabilities”:{“app”:"/Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk",“appPackage”:“com.poqstudio.app.platform.poquat”,“noReset”:false,“automationName”:“UiAutomator2”,“platformName”:“Android”,“deviceName”:“Android Device”},“capabilities”:{“alwaysMatch”:{“appium:app”:"/Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk",“appium:appPackage”:“com.poqstudio.app.platform.poquat”,“appium:automationName”:“UiAutomator2”,“appium:deviceName”:“Android Device”,“appium:noReset”:false,“platformName”:“android”},“firstMatch”:[{}]}}e[39m
[debug] e[35m[W3C]e[39m Calling AppiumDriver.createSession() with args: [{“app”:"/Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk",“appPackage”:“com.poqstudio.app.platform.poquat”,“noReset”:false,“automationName”:“UiAutomator2”,“platformName”:“Android”,“deviceName”:“Android Device”},null,{“alwaysMatch”:{“appium:app”:"/Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk",“appium:appPackage”:“com.poqstudio.app.platform.poquat”,“appium:automationName”:“UiAutomator2”,“appium:deviceName”:“Android Device”,“appium:noReset”:false,“platformName”:“android”},“firstMatch”:[{}]}]
[debug] e[35m[BaseDriver]e[39m Event ‘newSessionRequested’ logged at 1562580308565 (11:05:08 GMT+0100 (British Summer Time))
e[35m[BaseDriver]e[39m The capabilities [“fullReset”] are not standard capabilities and should have an extension prefix
e[35m[Appium]e[39m Appium v1.13.0 creating new AndroidUiautomator2Driver (v1.33.1) session
e[35m[Appium]e[39m Capabilities:
e[35m[Appium]e[39m platformName: android
e[35m[Appium]e[39m app: /Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk
e[35m[Appium]e[39m appPackage: com.poqstudio.app.platform.poquat
e[35m[Appium]e[39m automationName: UiAutomator2
e[35m[Appium]e[39m deviceName: Android Device
e[35m[Appium]e[39m noReset: false
e[35m[Appium]e[39m fullReset: true
[debug] e[35m[BaseDriver]e[39m W3C capabilities {“alwaysMatch”:{“platformNa… and MJSONWP desired capabilities {“fullReset”:true,“app”:”/U… were provided
[debug] e[35m[BaseDriver]e[39m Creating session with W3C capabilities: {“alwaysMatch”:{"platformNa…
e[35m[BaseDriver]e[39m Session created with session id: 68900c24-5369-48a9-b686-42f36f6e2e70
e[35m[BaseDriver]e[39m Using local app ‘/Users/krishnakiran/Desktop/MobileAutomationFramework-master/app-poquat-release.apk’
[debug] e[35m[UiAutomator2]e[39m Checking whether app is actually present
e[35m[ADB]e[39m The ANDROID_HOME environment variable is not set to the Android SDK root directory path. ANDROID_HOME is required for compatibility with SDK 23+. Checking along PATH for adb.
[debug] e[35m[UiAutomator2]e[39m Deleting UiAutomator2 session
[debug] e[35m[BaseDriver]e[39m Event ‘newSessionStarted’ logged at 1562580308745 (11:05:08 GMT+0100 (British Summer Time))
[debug] e[35m[W3C]e[39m Encountered internal error running command: Error: Could not find ‘adb’ in PATH. Please set the ANDROID_HOME environment variable with the Android SDK root directory path.
[debug] e[35m[W3C]e[39m at ADB. (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/appium-adb/lib/tools/system-calls.js:135:11)
[debug] e[35m[W3C]e[39m at Generator.throw ()
[debug] e[35m[W3C]e[39m at asyncGeneratorStep (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/@babel/runtime/helpers/asyncToGenerator.js:3:24)
[debug] e[35m[W3C]e[39m at _throw (/Applications/Appium.app/Contents/Resources/app/node_modules/appium/node_modules/@babel/runtime/helpers/asyncToGenerator.js:29:9)
e[35m[HTTP]e[39m e[37m<-- POST /wd/hub/session e[39me[31m500e[39m e[90m274 ms - 803e[39m
e[35m[HTTP]e[39m e[90me[39m
It is impossible to create a new session because ‘createSession’ which takes HttpClient, InputStream and long was not found or it is not accessible
Build info: version: ‘3.12.0’, revision: ‘7c6e0b3’, time: ‘2018-05-08T14:04:26.12Z’
System info: host: ‘POQ0026.local’, ip: ‘fe80:0:0:0:10de:7d73:bad7:e4fe%en0’, os.name: ‘Mac OS X’, os.arch: ‘x86_64’, os.version: ‘10.14.4’, java.version: ‘1.8.0_201’
Driver info: driver.version: AndroidDriver

Hello,

I am also getting following error, even after setting evn variables, plz help

Appium Verison - v1.14.0

Path Variables
C:\Users\user\android-sdks\platform-tools
C:\Users\user\android-sdks\tools
C:\Users\user\android-sdks\build-tools

Caused by: org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: Could not find ‘aapt.exe’ in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path.
Build info: version: ‘3.141.59’, revision: ‘e82be7d358’, time: ‘2018-11-14T08:25:53’
System info: host: ‘RAVINDRA’, ip: ‘192.168.100.4’, os.name: ‘Windows 8.1’, os.arch: ‘amd64’, os.version: ‘6.3’, java.version: ‘1.8.0_20’
Driver info: driver.version: AndroidDriver
remote stacktrace: UnknownError: An unknown server-side error occurred while processing the command. Original error: Could not find ‘aapt.exe’ in PATH. Please set the ANDROID_HOME or ANDROID_SDK_ROOT environment variables to the corect Android SDK root directory path.
at getResponseForW3CError (C:\Users\91963\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\errors.js:826:9)
at asyncHandler (C:\Users\91963\AppData\Roaming\npm\node_modules\appium\node_modules\appium-base-driver\lib\protocol\protocol.js:447:37)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.W3CHandshakeResponse.lambda$errorHandler$0(W3CHandshakeResponse.java:62)
at org.openqa.selenium.remote.W3CHandshakeResponse$$Lambda$185/460201727.apply(Unknown Source)
at org.openqa.selenium.remote.HandshakeResponse.lambda$getResponseFunction$0(HandshakeResponse.java:30)
at org.openqa.selenium.remote.HandshakeResponse$$Lambda$180/671046933.apply(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.lambda$createSession$0(ProtocolHandshake.java:126)
at org.openqa.selenium.remote.ProtocolHandshake$$Lambda$181/1765795529.apply(Unknown Source)
at java.util.stream.ReferencePipeline$3$1.accept(Unknown Source)
at java.util.Spliterators$ArraySpliterator.tryAdvance(Unknown Source)
at java.util.stream.ReferencePipeline.forEachWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyIntoWithCancel(Unknown Source)
at java.util.stream.AbstractPipeline.copyInto(Unknown Source)
at java.util.stream.AbstractPipeline.wrapAndCopyInto(Unknown Source)
at java.util.stream.FindOps$FindOp.evaluateSequential(Unknown Source)
at java.util.stream.AbstractPipeline.evaluate(Unknown Source)
at java.util.stream.ReferencePipeline.findFirst(Unknown Source)
at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:128)
… 39 more