Problem in android build of ionic "Failed to find 'ANDROID_HOME' environment variable"

0

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

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 properly configured

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 below.

/home/leonardo/Android/Sdk

The tools and platform-tools directory is within 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 an idea of what might be happening?

    
asked by anonymous 09.06.2016 / 19:02

3 answers

0

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

    
13.06.2016 / 15:40
1

Is not permission problem in the Android directory?

Before checking permissions, try assigning each variable separately to make it easier:

In my case, I use MAC and do it that way and I've never had problems (directories can 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
    
09.06.2016 / 19:32
0

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

    
01.10.2017 / 04:39