ANDROID_HOME environment variable issues with Appium - android

I am trying to run Appium on the command line with OSX El Capitan to test an Android application. I have been able to use Appium many times with the GUI version but have not had the same luck in the terminal. The issues I am facing stem from setting the $ANDROID_HOME environment variable. I have read other posts regarding this problem but the solutions have not helped me.
I have the following in my bash_profile :
export ANDROID_HOME=/Users/adamjakiela/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
I then run source ~/.bash_profile and am able to start the SDK by running the android command. I can also print the environment variable:
echo $ANDROID_HOME
/Users/adamjakiela/Library/Android/sdk
But then, when I run Appium on the command line I receive the following message which eventually leads to other problems:
warn: The ANDROID_HOME environment variable is not set to the Android SDK root directory path.
I can also run the Appium doctor and see the following:
Running Android Checks
✖ ANDROID_HOME is not set
Appium-Doctor detected problems. Please fix and rerun Appium-Doctor.
Additionally, I have installed all the build tools for the applicable versions of Android and have had no problem build my applications or using the Appium GUI version by pointing it to the $ANDROID_HOME location.
Why are the errors shown by Appium inconsistant with the fact that the $ANDROID_HOME environment variable is set and that other applications are able to use the Android SDK?

Related

UI Automator doesn't start in OSX

yogevabergel [~/Library/Android/sdk/tools/bin] $ ./uiautomatorviewer
-Djava.ext.dirs=/Users/yogevabergel/Library/Android/sdk/tools/lib/x86_64:/Users/yogevabergel/Library/Android/sdk/tools/lib is not supported. Use -classpath instead.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Any help? Nothing in the internet about it.
First, check you set properly system variables like JAVA_HOME & ANDROID_HOME and that tools are in place, easy way is to use appium-doctor for this:
npm appium-doctor -g
appium-doctor --android
And fix any error you get.
It can be also that you miss some component in android-sdk-tools:
Launch Android Studio
Configure => SDK manager
On SDK Tools tab check status for Platform-Tools & SDK Tools, update if possible
Which java version are you running?
I hit the same issue with Java v.10, installed Java v.8, updated ~/.bash_profile with
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
and it helped.

sudo ionic run android not working

I am trying to run a hybrid app on my android phone using ionic using the following command:
sudo ionic run android
However I keep receiving this error :
Error: Failed to find 'ANDROID_HOME' environment variable. Try setting
setting it manually. Failed to find 'android' command in your 'PATH'.
Try update your 'PATH' to include path to valid SDK directory.
I have already added platform tools & tools to PATH updated ANDROID_HOME to point to my sdk root.
The ANDROID_HOME environment variable shows up when I run env and the PATH has the tools and platform tools too. Additionally I can execute android too. It launches the SDK Manager as expected.
Details:
ANDROID_HOME: /home/user/Android/Sdk
$PATH: /home/user/Android/Sdk/tools:/home/user/Android/Sdk/platform-tools
Please help! This is driving me up the wall!
Credit for this goes to #heemayl on AskUbuntu.
https://askubuntu.com/a/783805/247116
sudo sanitizes the environment and by default only keeps certain
environment variables available with modifying the values of some
(e.g. PATH).
You can pass the variable ANDROID_HOME manually:
sudo ANDROID_HOME="/actual/path" ionic run android
Or preserve the current environment:
sudo -E ionic run android

Meteor - Installing android platform cant find ANDROID_HOME variable

When I tried to install the Android platform, I get a error that the environment variable ANDROID_HOME cant be found, but if I echo it, it proves it exists.
Let me walk you to it:
1) Lets create a new app
dbugger#mercury:~/projects/meteor$ meteor create test
Created a new Meteor app in 'test'.
To run your new app:
cd test
meteor
If you are new to Meteor, try some of the learning resources here:
https://www.meteor.com/learn
2) So far, so good. Lets now install the android platform
dbugger#mercury:~/projects/meteor$ cd test/
dbugger#mercury:~/projects/meteor/test$ meteor add-platform android --verbose
Writing new config.xml
Creating Cordova project
% Creating a new cordova project.
Adding platform Android to Cordova project
=> Errors executing Cordova commands:
While adding platform Android to Cordova project:
Cordova error: CordovaError: Failed to fetch platform android
Probably this is either a connection problem, or platform spec is incorrect.
Check your connection and platform name/version/URL.
undefined
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/cordova/platform.js:270:25
at _rejected (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:797:24)
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:823:30
at Promise.when (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:1035:31)
at Promise.promise.promiseDispatch (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:741:41)
at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:557:44
at flush (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:448:13)
(If the error message contains suggestions for a fix, note that this may not apply to the Meteor integration. You can try running again with the --verbose option to help diagnose the issue.)
3) Well, that did not work out so well. Let's try with sudo
dbugger#mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose
Adding platform Android to Cordova project
% Adding android project...
android: added platform
Checking Cordova requirements for platform Android
Your system does not yet seem to fulfill all requirements to build apps for Android.
Please follow the installation instructions here:
https://github.com/meteor/meteor/wiki/Mobile-Development-Install:-Android-on-Linux
Status of the requirements:
✓ Java JDK
✗ Android SDK: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to include path to valid SDK directory.
✗ Android target: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
✗ Gradle: Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.
Might need to install Android SDK or set up 'ANDROID_HOME' env variable.
4) Wait, what? Im sure that environment variable is set. Let's check it.
dbugger#mercury:~/projects/meteor/test$ echo $ANDROID_HOME
/home/dbugger/Android/Sdk
5) I knew it! So why did it fail...? Let's check it up again
dbugger#mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose
While adding platforms:
error: android: platform is already added
What?! Now it turns out that it DID install in the end?? What is going on here? I suspect something is greatly misconfigured in my system, but I am not sure what...
you are using sudo!
you probably shouldn't
even if the ANDROID_HOME variable is defined for your current user does not mean it is also defined for the root user, which is what the environment of the sudo call will be.
I'd really recommend against using sudo for meteor. If you can avoid that, then it should work and your problem is solved. Otherwise make sure to define the ANDROID_HOME variable also for the root user, or just use
sudo env ANDROID_HOME=[whatever you want it to be] meteor
instead.

Meteor 1.2 Failed to find ANDROID_HOME

Problem: Meteor cannot find my Android SDK when I try to meteor add-platform android on Linux Mint.
I've set my PATH variable: (echo $PATH)
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/jimmy/Android/Sdk/tools:/home/jimmy/Android/Sdk/platform-tools
I've got my ANDROID_HOME variable: (echo $ANDROID_HOME)
/home/jimmy/Android/Sdk
But still, when I run sudo meteor add-platform android --verbose I get:
Adding platform Android to Cordova project
% Adding android project...
android: added platform
Checking Cordova requirements for platform Android
Your system does not yet seem to fulfill all requirements to build apps for
Android.
Please follow the installation instructions here:
https://github.com/meteor/meteor/wiki/Mobile-Development-Install:-Android-on-Linux
Status of the requirements:
✓ Java JDK
✗ Android SDK: Failed to find 'ANDROID_HOME' environment variable. Try setting
setting it manually.
Failed to find 'android' command in your 'PATH'. Try update your 'PATH' to
include path to valid SDK directory.
✗ Android target: Android SDK not found. Make sure that it is installed. If it
is not at the default location, set the ANDROID_HOME environment variable.
✗ Gradle: Could not find gradle wrapper within Android SDK. Could not find
Android SDK directory.
Might need to install Android SDK or set up 'ANDROID_HOME' env variable.
Okay, so I figured it out? (I guess)
So, I had already had my PATH and ANDROID_HOME set and everything, I could do echo $PATH and echo $ANDROID_HOME and it would print fine; but when I would run the different commands, it wouldn't work.
however, when I run sudo -s and then the commands, it works fine.
Cheers
ANDROID_HOME must be set to Android/Sdk folder. In my case (Ubuntu) it is:
export ANDROID_HOME="/home/***<user name>***/Android/Sdk"
export PATH=$PATH:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
Put this lines at the end of ~/.profile:
$ gedit ~/.profile
Then $ source ~/.profile
I had the same issue (and now I am stuck to Android target), but to solve Android SDK,
go to Android studio and ensure you remove everything from Android 6,
then that you have Android 5.1.1 installed (with v22 of the platform),
restart your console (I had to restart the laptop)
and normally it doesnt appear again (btw you dont need to use sudo normally)
It's possible that since you're using SUDO - that the PATH / ANDROID_HOME are not present in the root user's session. So try either:
sudo -s
export PATH=...
export ANDROID_HOME=...
meteor ...
or avoid using sudo.

Does not recognize android command in path

I'm triying to build my first cordova project, when I'm inside the project folder i tip:
sudo cordova build android
and I get the following error:
[Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.]
ERROR building one of the platforms: Error: /home/veritopsecret/hello/platforms/android/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
when I do echo $PATH I get:
veritopsecret#veritopsecret-SATELLITE-PRO-C50-A-1HQ:~/hello$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/veritopsecret/Escriptori/android-sdk-linux/tools:/home/veritopsecret/Escriptori/android-sdk-linux/platform-tools
I have also modified .profile file, but it stills say that it hasn't android command in the PATH. However, if I just write android, it opens the android sdk manager. Help please!!
As I re-read your question, I see you run sudo cordova build android
I think the issue you have is that you define ANDROID_HOME and add the android tools to the path of your user but then you use sudo to run the build.
sudo runs with elevated privileges using a user which is not your user profile that you are logged with, so the path and ANDROID_HOME are not set. (maybe try sudo echo $PATH to be sure of that).
So if you really wanted to use sudo to build, you would need either to define the vars for the sudo user or use instead sudo -E (see this page for more details : https://wiki.archlinux.org/index.php/Sudo#Environment_variables)
But actually, you should be using sudo only when installing cordova, not when using the CLI.
So, just run cordova build android and everything should be fine.

Categories

Resources