Ionic android build Error - Failed to find 'ANDROID_HOME' environment variable

前端 未结 12 1453
庸人自扰
庸人自扰 2020-12-23 19:41

I am trying to build android for ionic in linux but its showing me an error like this

     [Error: Failed to find \'ANDROID_HOME\' environment variable. 
           


        
相关标签:
12条回答
  • 2020-12-23 19:45

    Android Home should be the root folder of SDK.

    export ANDROID_HOME="$HOME/android-sdk-linux"
    

    EDIT: Open terminal and type these commands. (yes, on a ternimal , not in bashrc file)

    export ANDROID_HOME=~/android-sdk-macosx
    PATH=$PATH:$ANDROID_HOME/tools
    PATH=$PATH:$ANDROID_HOME/platform-tools    
    

    and then in the same terminal just type android. If configured you would be able to use build commands from this terminal. (it's a temporary solution)

    0 讨论(0)
  • 2020-12-23 19:48

    You only have to edit your profile file like this:

    sudo su
    vim ~/.profile
    

    and put this at the end of the file:

    export ANDROID_HOME=/home/(user name)/Android/Sdk
    export PATH=$PATH:/tools
    export PATH=$PATH:/platform-tools
    

    Save and close the file and do:

    cd ~
    source .profile
    

    now if you do:

    echo $ANDROID_HOME
    

    it should show you something like this:

    /home/(user name)/Android/Sdk
    
    0 讨论(0)
  • 2020-12-23 19:50

    I had this problem when running sudo ionic run android as root as these environmental variables were not persisted. Fixed by running sudo -E ionic run android.

    0 讨论(0)
  • 2020-12-23 19:59

    For OSX

    • into ~/.bash_profile add:

      export ANDROID_HOME="/path/to/android-sdk-macosx"
      export PATH="$ANDROID_HOME/platform-tools:$ANDROID_HOME/tools:$PATH"
      

      and then execute it in terminal to take effect immediately;

    • into /etc/sudoers add: (you can use console: sudo visudo)

      Defaults        env_keep += "ANDROID_HOME"
      

      since the building process has to start with sudo and Node's process.env get the respective variables.

    0 讨论(0)
  • 2020-12-23 20:02

    Download the android SDK http://developer.android.com/sdk/installing/index.html

    You only export the path of SDK folder.

    export ANDROID_HOME="YOUR_PATH/sdk/"

    0 讨论(0)
  • 2020-12-23 20:02

    The procedure is already well explained in the above answers. But if add the ANDROID_HOME and PATH to the .bashrc or .zshrc present in /home/username/ and try to run the ionic command with sudo, you may get this error again.

    The reason is, it may look for the ANDROID_HOME and PATH in the .zshrc file of root user instead of currently logged in user. So you shouldn't do that unless you add that in root user's .bashrc or .zshrc files.

    0 讨论(0)
提交回复
热议问题