[SOLVED] ANDROID_HOME doesn't work anymore (?)

Hi everyone, happy to be part of ionic world.
I was exporting an android project in Mac OSX and I have the known error:

ERROR: Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions.

I fixed that issue a while ago (like a month ago) but today is still there!
The “.bash_profile” contains all the needed:

export ANDROID_HOME=/System/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home)

I can’t figure out why it doesn’t work just since today! There are no android sdk updates too.

Any help about what should be the issue? Thanks

1 Like

Sometimes it’s an issue with directory and file permissions

Thanks for the reply.
I’ve set all the sdk folder permission to everyone but still not work…

Not only read access, scripts must be executable too.

Read and Write of course :blush:

Write is not necessary it’s +x that is required on both drectories and executables like android, adb

sudo chmod 777 /System/android-sdk-macosx/

Still not work :expressionless:

What does it say when you type android in a terminal?

When In Doubt: Reboot! :wink:

It open the android SDK manager. On reboot: same issue

Where do you set these env variables?

In the “~/.bash_profile” file. You can see the content in the first post.
It makes no sense to me! Why yesterday was fine and today is not! Grrrr…

Does this happens only in XCode? have you tried to use only command line tools?

ionic run android

or

ionic build android

Both. I use only command line plus the android project can’t be build in Xcode.
This is the build error (the run one is similar):

[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: /Users/Norman/Sites/AppMobile/iWish/platforms/android/cordova/build: Command failed with exit code 2
        You may not have the required environment or OS to build this project
        Error: /Users/Norman/Sites/AppMobile/iWish/platforms/android/cordova/build: Command failed with exit code 2
            at ChildProcess.whenDone (/usr/local/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
            at ChildProcess.emit (events.js:110:17)
            at maybeClose (child_process.js:1015:16)
            at Process.ChildProcess._handle.onexit (child_process.js:1087:5)

Well good luck, I have no clue.
I had a similar problem and I looked at the cordova js source code to understand under which conditions this error message was issued and then I printed some values from the script itself.

I have no clue too, that’s why I’ve asked help. It’s a stupid and no-sense issue!
NO! I’VE TRIED TO BUILD A BRAND NEW APP AND… NO ERRORS! I’m working on that app since a couple of month! I MUST build that! Advise about that?

If i’m trying to build the android versione without the sudo this is the error:
rm: could not remove directory (code EACCES): /Users/…

Have you tried to remove android platform in your project and then re-add it?

You should not be required to use sudo if you had installed node as non privileged user by using nvm. Many node/npm issues come from this bad way of installing it.

FIXED! HERE THE SOLUTION! (just if you have all working well, so it worked at least one!)

Problem:
You’re working well with your Ionic app when a sad day the ANDROID_HOME error is shown.
What should be the problem? Maybe you’ve worked with some other framework like crashlytics to manage beta and crashes.

Solution:
The permissions are changed (probably) so make the following:

  1. Restore the right folder permission to all the folder/subfolder of the platforms folder
  2. Delete the android platform with “sudo ionic platform remove android”
  3. Add the android platform with “ionic platform add android” DON’T USE THE SUDO! If there are errors without the sudo SO that’s the problem! NEVER use the sudo thing or the project will have issue like this!

I’ve think the same thing @gmarziou when I sent the post. I’ve found the fix because the new project didn’t ask for admin password but the old one does.
We get it at the same time :smile: Thanks for the support!

FINALLY I can go on! I hope this can help you, dude that is reading this :wink:

3 Likes

EXCELLENT!!! I wish I’ve found this post earlier, there’s tons of posts with this exact same problem opened without any solution that actually works… I spent nearly a week messing with the system env paths, re-downloading and re-installing the big Android SDK (takes hours with my Internet speed), thinking that I was doing it wrong…

I don’t remember which module/framework that changed the permissions of some files/folders, but I can tell it happened because at one point I had to restore the permissions of “package.json” otherwise it wouldn’t let me install other modules without using “sudo”…

well, yea… I can move on also …

THANKS!! A LOT!!

Best Regards :smile:

How cool is to read that kind of answer! This is how the community should work :smile:
Good to know that it worked for you. Good coding then :blush: