Ionic android build Error - Failed to find 'AN

2019-01-31 10:55发布

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. 
      Try setting setting it manually.
      Failed to find 'android' command in your 'PATH'. 
      Try update your 'PATH' to include path to valid SDK directory.]
      ERROR building one of the platforms: Error: /home/kumar/myapp/platforms/android/cordova/build: Command failed with exit code 2
      You may not have the required environment or OS to build this project
      Error: /home/kumar/myapp/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:139:23)
at ChildProcess.EventEmitter.emit (events.js:98:17)
at maybeClose (child_process.js:743:16)
at Process.ChildProcess._handle.onexit (child_process.js:810:5)

and i've added this in my bashrc file

export ANT_HOME="/usr/bin/ant"
export PATH="$PATH:$ANT_HOME/bin"
export HOME="/home/kumar"
export ANDROID_HOME="$HOME/android-sdk-linux/tools"
export ANDROID_PLATFORM_TOOLS="$HOME/android-sdk-linux/platform-tools"
export PATH="$ANDROID_HOME:$ANDROID_PLATFORM_TOOLS:$PATH"

I'm thinking i've given the path but i dont know why its showing me this error .. Please help....

12条回答
趁早两清
2楼-- · 2019-01-31 11:19

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)

查看更多
看我几分像从前
3楼-- · 2019-01-31 11:19

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.

查看更多
Ridiculous、
4楼-- · 2019-01-31 11:21

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/"

查看更多
Melony?
5楼-- · 2019-01-31 11:25

Setup for Ubuntu

  1. download Android Studio or SDK only
  2. install
  3. set PATH

In my case Android and its SDK was installed by default under:

/root/Android/Sdk

Open terminal and edit ~/.bashrc

sudo su
vim ~/.bashrc

Export ANDROID_HOME and add folders with binaries to your PATH

export ANDROID_HOME=/root/Android/Sdk
PATH=$PATH:$ANDROID_HOME/tools
PATH=$PATH:$ANDROID_HOME/platform-tools

To refresh your PATH run

source ~/.bashrc

When ionic build android still fails it could be because of wrong sdk version. To install correct versions and images run android from command line. Since it is now in your PATH you should be able to run it from anywhere.

查看更多
【Aperson】
6楼-- · 2019-01-31 11:25

In my Case: I have put the correct path for Android and java but still getting the error.

The problem was that I have added the Android platform using sudo command.sudo ionic cordova platform android.

To solve my problem: First I have removed the platform android by running command

sudo ionic cordova platform rm android

then add the android platform again with out sudoionic cordova platform add android but i get the error of permissions.

To resolve the error run command

sudo chmod -R 777 {Path-of-your-project}

in my case sudo chmod -R 777 ~/codebase/IonicProject Then run command

ionic cordova platform add android

or

ionic cordova run android

查看更多
三岁会撩人
7楼-- · 2019-01-31 11:29

Windows - set environment variable permanently:

setx ANDROID_HOME "C:\Program Files\Android\android-sdk"

or

setx ANDROID_HOME "C:\Program Files (x86)\Android\android-sdk"

查看更多
登录 后发表回答