Ionic Android Build Problem "Failed to find 'ANDROID_HOME' Environment variable"

Asked

Viewed 1,806 times

0

I tried several answers to the below error found right here in the OS but none solved the problem. Running the command sudo ionic build android is returned the following message

Error: Failed to find 'ANDROID_HOME' environment variable. Try setting setting it manually.
Detected 'android' command at /opt/android-studio/bin but no 'tools' directory found near.
Try reinstall Android SDK or update your PATH to include path to valid SDK directory.

ANDROID_HOME and PATH environment variables appear to be configured correctly

leonardo@antunesleo:~/projects/devcoffee/coffee-force$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/leonardo/Android/Sdk/tools:/home/leonardo/Android/Sdk/platform-tools

leonardo@antunesleo:~/projects/devcoffee/coffee-force$ echo $ANDROID_HOME
/home/leonardo/Android/Sdk

My Sdk is in the directory shown below.

/home/leonardo/Android/Sdk

the tools and Platform-tools directory is inside the Sdk, as expected.

leonardo@antunesleo:~/Android/Sdk$ ls
add-ons  build-tools  extras  licenses  Link para SDK Readme.txt  platforms  platform-tools  SDK Readme.txt  sources  tools

Does anyone have any idea what might be going on?

3 answers

1

Will it is not permission problem in Android directory?

Before checking permissions, try assigning each variable separately for ease:

In my case I use MAC and do so and never had problems (directories may vary, of course) :

export ANDROID_HOME="/Users/<user_name>/Library/Android/sdk"
export ANDROID_TOOLS="/Users/<user_name>/Library/Android/sdk/tools/"
export ANDROID_PLATFORM_TOOLS="/Users/<user_name>/Library/Android/sdk/platform-tools/"
PATH=$PATH:$ANDROID_HOME:$ANDROID_TOOLS:$ANDROID_PLATFORM_TOOLS
echo $PATH

0


The problem was in the "sudo" before the execution of the command ionic build. Apparently in Ubuntu sudo uses different paths. He was using sudo because without it he was informed that he was not allowed to execute the command. I gave full permission to the project files/repository and ran the ionic build without the sudo in front, solved the problem!

0

The problem is due to linux root permissions, you can use the sudo chown -R user project folder command

Browser other questions tagged

You are not signed in. Login or sign up in order to post.