Ionic android构建错误——未能找到“ANDROID_HOME”环境变量

时间:2021-06-06 23:12:10

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

我正在尝试在linux中为ionic构建android,但是它给我带来了这样的错误。

     [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

我在bashrc文件中添加了这个

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 个解决方案

#1


49  

Android Home should be the root folder of SDK.

Android Home应该是SDK的根文件夹。

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

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

编辑:打开终端,输入这些命令。(是的,在ternimal上,不是bashrc文件)

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)

然后在同一个终端中输入android。如果配置好,您将能够使用来自此终端的构建命令。(这是一个临时的解决方案)

#2


14  

For OSX

  • into ~/.bash_profile add:

    到~ /。bash_profile添加:

    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)

    在/etc/sudoers中添加:(您可以使用控制台: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.

    因为构建过程必须从sudo和Node的过程开始。env得到各自的变量。

#3


9  

Case: using SO Windows, try:

案例:使用SO Windows,请尝试:

set ANDROID_HOME=C:\\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

more in: http://spring.io/guides/gs/android/

更多:http://spring.io/guides/gs/android/

Case: you don't have platform-tools:

案例:你没有平台工具:

cordova platforms list
cordova platforms add <Your_platform, example: Android>

#4


8  

Setup for Ubuntu

  1. download Android Studio or SDK only
  2. 只下载Android Studio或SDK
  3. install
  4. 安装
  5. set PATH
  6. 设置路径

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

在我的案例中,Android和它的SDK是默认安装的:

/root/Android/Sdk

Open terminal and edit ~/.bashrc

打开终端并编辑~/.bashrc

sudo su
vim ~/.bashrc

Export ANDROID_HOME and add folders with binaries to your PATH

导出ANDROID_HOME并向路径添加带有二进制文件的文件夹

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.

当ionic构建android仍然失败时,可能是因为错误的sdk版本。从命令行安装运行android的正确版本和图像。既然它现在在您的路径中,您应该能够从任何地方运行它。

#5


6  

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

下载android SDK http://developer.android.com/sdk/installing/index.html

You only export the path of SDK folder.

您只导出SDK文件夹的路径。

export ANDROID_HOME="YOUR_PATH/sdk/"

出口ANDROID_HOME = " YOUR_PATH / sdk /”

#6


5  

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.

上面的答案已经很好地解释了这个过程。但是,如果将ANDROID_HOME和路径添加到/home/username/中显示的.bashrc或.zshrc中,并尝试使用sudo运行ionic命令,则可能再次出现此错误。

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.

原因是,它可以在根用户的.zshrc文件中查找ANDROID_HOME和路径,而不是当前登录的用户。所以你不应该这样做,除非你在根用户的。bashrc或者。zshrc文件中添加。

#7


4  

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.

我在运行sudo ionic作为根运行android时遇到了这个问题,因为这些环境变量没有持久化。通过运行sudo -E ionic运行android修复。

#8


3  

Windows - set environment variable permanently:

Windows -永久设置环境变量:

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

对于setx ANDROID_HOME“C:\ Program Files \ Android \ Android sdk”

or

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

setx ANDROID_HOME“C:\程序文件(x86)\Android\ Android -sdk”

#9


2  

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

#10


0  

For OSX

Great tutorial here: https://www.youtube.com/watch?v=kY22NSBwV_s

伟大的教程:https://www.youtube.com/watch?v=kY22NSBwV_s

No need to do any bash commands/symlinks:

不需要做任何bash命令/符号链接:

  1. Install Java 6 runtime: https://support.apple.com/kb/DL1572?locale=de_DE
  2. 安装Java 6运行时:https://support.apple.com/kb/dl1572?
  3. Install Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  4. 安装Java JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8 -下载- 2133151. - html

#11


0  

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

在我的例子中:我为Android和java设置了正确的路径,但仍然得到了错误。

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

问题是我使用sudo命令添加了Android平台。sudo ionic cordova平台android。

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

为了解决我的问题:首先我通过运行命令删除了平台android

sudo ionic cordova platform rm android

sudo ionic cordova站台rm android

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

然后再添加一个android平台,再添加一个sudoionic cordova平台,再添加一个android,我得到了权限错误。

To resolve the error run command

要解决错误运行命令

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

sudo chmod -R 777(您的项目路径)

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

在我的例子中,sudo chmod - r777 ~/codebase/IonicProject然后运行命令

ionic cordova platform add android

ionic cordova平台添加android

or

ionic cordova run android

离子科尔多瓦运行android

#12


0  

To add ANDROID_HOME value permanently,

要永久添加ANDROID_HOME值,

gedit ~/.bashrc

and add the following lines

并添加以下几行

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

Save the file and you need not update ANDROID_HOME value everytime.

保存文件,您不需要每次都更新ANDROID_HOME值。

#1


49  

Android Home should be the root folder of SDK.

Android Home应该是SDK的根文件夹。

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

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

编辑:打开终端,输入这些命令。(是的,在ternimal上,不是bashrc文件)

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)

然后在同一个终端中输入android。如果配置好,您将能够使用来自此终端的构建命令。(这是一个临时的解决方案)

#2


14  

For OSX

  • into ~/.bash_profile add:

    到~ /。bash_profile添加:

    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)

    在/etc/sudoers中添加:(您可以使用控制台: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.

    因为构建过程必须从sudo和Node的过程开始。env得到各自的变量。

#3


9  

Case: using SO Windows, try:

案例:使用SO Windows,请尝试:

set ANDROID_HOME=C:\\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

more in: http://spring.io/guides/gs/android/

更多:http://spring.io/guides/gs/android/

Case: you don't have platform-tools:

案例:你没有平台工具:

cordova platforms list
cordova platforms add <Your_platform, example: Android>

#4


8  

Setup for Ubuntu

  1. download Android Studio or SDK only
  2. 只下载Android Studio或SDK
  3. install
  4. 安装
  5. set PATH
  6. 设置路径

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

在我的案例中,Android和它的SDK是默认安装的:

/root/Android/Sdk

Open terminal and edit ~/.bashrc

打开终端并编辑~/.bashrc

sudo su
vim ~/.bashrc

Export ANDROID_HOME and add folders with binaries to your PATH

导出ANDROID_HOME并向路径添加带有二进制文件的文件夹

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.

当ionic构建android仍然失败时,可能是因为错误的sdk版本。从命令行安装运行android的正确版本和图像。既然它现在在您的路径中,您应该能够从任何地方运行它。

#5


6  

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

下载android SDK http://developer.android.com/sdk/installing/index.html

You only export the path of SDK folder.

您只导出SDK文件夹的路径。

export ANDROID_HOME="YOUR_PATH/sdk/"

出口ANDROID_HOME = " YOUR_PATH / sdk /”

#6


5  

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.

上面的答案已经很好地解释了这个过程。但是,如果将ANDROID_HOME和路径添加到/home/username/中显示的.bashrc或.zshrc中,并尝试使用sudo运行ionic命令,则可能再次出现此错误。

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.

原因是,它可以在根用户的.zshrc文件中查找ANDROID_HOME和路径,而不是当前登录的用户。所以你不应该这样做,除非你在根用户的。bashrc或者。zshrc文件中添加。

#7


4  

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.

我在运行sudo ionic作为根运行android时遇到了这个问题,因为这些环境变量没有持久化。通过运行sudo -E ionic运行android修复。

#8


3  

Windows - set environment variable permanently:

Windows -永久设置环境变量:

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

对于setx ANDROID_HOME“C:\ Program Files \ Android \ Android sdk”

or

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

setx ANDROID_HOME“C:\程序文件(x86)\Android\ Android -sdk”

#9


2  

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

#10


0  

For OSX

Great tutorial here: https://www.youtube.com/watch?v=kY22NSBwV_s

伟大的教程:https://www.youtube.com/watch?v=kY22NSBwV_s

No need to do any bash commands/symlinks:

不需要做任何bash命令/符号链接:

  1. Install Java 6 runtime: https://support.apple.com/kb/DL1572?locale=de_DE
  2. 安装Java 6运行时:https://support.apple.com/kb/dl1572?
  3. Install Java JDK: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
  4. 安装Java JDK:http://www.oracle.com/technetwork/java/javase/downloads/jdk8 -下载- 2133151. - html

#11


0  

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

在我的例子中:我为Android和java设置了正确的路径,但仍然得到了错误。

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

问题是我使用sudo命令添加了Android平台。sudo ionic cordova平台android。

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

为了解决我的问题:首先我通过运行命令删除了平台android

sudo ionic cordova platform rm android

sudo ionic cordova站台rm android

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

然后再添加一个android平台,再添加一个sudoionic cordova平台,再添加一个android,我得到了权限错误。

To resolve the error run command

要解决错误运行命令

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

sudo chmod -R 777(您的项目路径)

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

在我的例子中,sudo chmod - r777 ~/codebase/IonicProject然后运行命令

ionic cordova platform add android

ionic cordova平台添加android

or

ionic cordova run android

离子科尔多瓦运行android

#12


0  

To add ANDROID_HOME value permanently,

要永久添加ANDROID_HOME值,

gedit ~/.bashrc

and add the following lines

并添加以下几行

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

Save the file and you need not update ANDROID_HOME value everytime.

保存文件,您不需要每次都更新ANDROID_HOME值。