无法找到'ANDROID_HOME'环境变量

时间:2022-03-31 23:02:44

I am trying to build an ionic-android project and i have android sdk installed.

我正在尝试构建一个离子android项目,我安装了android sdk。

无法找到'ANDROID_HOME'环境变量

The name of my project is myApp.I have successfully added android platform to myApp. But when i tries to build the project

我的项目名称是myApp.I已成功将android平台添加到myApp。但是当我试图建立项目时

~/myApp$ sudo ionic build android

result is

结果是

Running command: /home/hari/myApp/hooks/after_prepare/010_add_platform_class.js /home/hari/myApp
  add to body class: platform-android
  ERROR building one of the platforms: 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.
You may not have the required environment or OS to build this project
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.

see the ANDROID_HOME and PATH variable

请参阅ANDROID_HOME和PATH变量

echo $ANDROID_HOME
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hari/Android/Sdk

echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/hari/Android/Sdk/tools:/home/hari/Android/Sdk/platform-tools:/usr/local/bin:/opt/gradle/bin

I have seen almost the same kind of questions on stack overflow, but none works for me. Is there anything wrong with my android-sdk configuration? How can i build this project?

我已经看到几乎同样的关于堆栈溢出的问题,但没有一个对我有用。我的android-sdk配置有什么问题吗?我该如何建立这个项目?

7 个解决方案

#1


118  

You may want to confirm that your development environment has been set correctly.

您可能需要确认已正确设置开发环境。

Quoting from spring.io:

引自spring.io:

Set up the Android development environment

Before you can build Android applications, you must install the Android SDK. Installing the Android SDK also installs the AVD Manager, a graphical user interface for creating and managing Android Virtual Devices (AVDs).

在构建Android应用程序之前,必须先安装Android SDK。安装Android SDK还会安装AVD Manager,这是一个用于创建和管理Android虚拟设备(AVD)的图形用户界面。

  1. From the Android web site, download the correct version of the Android SDK for your operating system.

    在Android网站上,为您的操作系统下载正确版本的Android SDK。

  2. Unzip the archive to a location of your choosing. For example, on Linux or Mac, you can place it in the root of your user directory. See the Android Developers web site for additional installation details.

    将存档解压缩到您选择的位置。例如,在Linux或Mac上,您可以将其放在用户目录的根目录中。有关其他安装详细信息,请参阅Android开发人员网站。

  3. Configure the ANDROID_HOME environment variable based on the location of the Android SDK. Additionally, consider adding ANDROID_HOME/tools, and ANDROID_HOME/platform-tools to your PATH.

    根据Android SDK的位置配置ANDROID_HOME环境变量。另外,请考虑在PATH中添加ANDROID_HOME / tools和ANDROID_HOME / platform-tools。

Mac OS X

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Linux

export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Windows

set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

The Android SDK download does not include specific Android platforms. To run the code in this guide, you need to download and install the latest SDK platform. You do this by using the Android SDK and AVD Manager that you installed in the previous section.

Android SDK下载不包含特定的Android平台。要运行本指南中的代码,您需要下载并安装最新的SDK平台。您可以使用上一节中安装的Android SDK和AVD Manager来完成此操作。

  1. Open the Android SDK Manager window:

    打开Android SDK Manager窗口:

    android
    

    Note: If this command does not open the Android SDK Manager, then your path is not configured correctly.

    注意:如果此命令未打开Android SDK Manager,则说明您的路径未正确配置。

  2. Select the Tools checkbox.

    选择“工具”复选框。

  3. Select the checkbox for the latest Android SDK.

    选中最新Android SDK的复选框。

  4. From the Extras folder, select the checkbox for the Android Support Library.

    在Extras文件夹中,选中Android Support Library的复选框。

  5. Click the Install packages... button to complete the download and installation.

    单击“安装包...”按钮以完成下载和安装。

    Note: You may want to install all the available updates, but be aware it will take longer, as each API level is a large download.

    注意:您可能希望安装所有可用的更新,但请注意它需要更长时间,因为每个API级别都是大型下载。

#2


25  

In Linux

在Linux中

First of all set ANDROID_HOME in .bashrc file

首先在.bashrc文件中设置ANDROID_HOME

Run command

运行命令

sudo gedit ~/.bashrc

set andoid sdk path where you have installed

设置已安装的andoid sdk路径

export ANDROID_HOME=/opt/android-sdk-linux 
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

to reload file run command

重新加载文件运行命令

source ~/.bashrc

Now check installed platform, run command

现在检查已安装的平台,运行命令

ionic platform

Output

产量

Installed platforms:
  android 6.0.0
Available platforms: 
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ubuntu ~4.3.4
  webos ~3.7.0

if android already installed then need to remove and install again

如果已安装android,则需要再次删除并安装

ionic platform rm android
ionic platform add android

If not installed already please add android platform

如果没有安装,请添加android平台

ionic platform add android

Please make sure you have added android platform without sudo command

请确保您已添加没有sudo命令的android平台

if you still getting error in adding android platfrom like following

如果你仍然在添加android platfrom时遇到错误,如下所示

Error: EACCES: permission denied, open '/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json'

错误:EACCES:权限被拒绝,打开'/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json'

Please go to /home/ubuntu/ and remove .cordova folder from there

请转到/ home / ubuntu /并从那里删除.cordova文件夹

cd /home/ubuntu/
sudo rm -r .cordova

Now run following command again

现在再次运行以下命令

ionic platform add android

after adding platform successfully you will be able to build andoid in ionic.

成功添加平台后,您将能够在离子中构建andoid。

Thanks

谢谢

#3


18  

These are the steps that you need to follow to successfully set up your Ionic Project to work with android emulator:

以下是成功设置Ionic项目以使用Android模拟器时需要遵循的步骤:

  1. Create an Ionic Project: ionic start appName tabs (for tab theme)
  2. 创建一个离子项目:ionic start appName标签(用于标签主题)
  3. cd appName
  4. cd appName
  5. ionic setup sass
  6. 离子设置sass
  7. To start the app on web: ionic serve
  8. 在web上启动应用程序:ionic serve

To add android platform:

要添加android平台:

Priori Things

First you need to setup the environment variables. For this you need to consider 3 files:

首先,您需要设置环境变量。为此,您需要考虑3个文件:

1. ~/.profile (For setting up the variables every time terminal opens or computer boots up):

1.~ / .profile(每次终端打开或计算机启动时设置变量):

//Code that you need to append at the last

//你需要在最后添加的代码

set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export ANDROID_HOME='/home/<user_name>/Android/Sdk' <Path to android SDK>
export PATH=$PATH:$ANDROID_HOME/bin
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

2. /etc/environment (to set the environment variables):

2. / etc / environment(设置环境变量):

//All the content of the file

//文件的所有内容

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
ANDROID_HOME="/home/<user_name>/Android/Sdk" <Path to android SDK>

3. /etc/profile:

3. / etc / profile:

//Code that you need to add at the last

//您需要在最后添加的代码

JAVA_HOME=/usr/lib/jvm/java-8-oracle <Path where Java is installed>
JRE_HOME=$JAVA_HOME/jre 
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

For loading the above changes made to the file you need to run the following command:

要加载对文件所做的上述更改,您需要运行以下命令:

source ~/.profile
source /etc/environment
source /etc/profile

Posteori Things

1. Add platform: ionic platform add android (Note that you need to run this command without sudo)

1.添加平台:离子平台添加android(注意你需要在没有sudo的情况下运行此命令)

2. If you are still getting error in the above command then do the following: (here appName = helloWorld)

2.如果在上述命令中仍然出现错误,请执行以下操作:(此处appName = helloWorld)

    cd ..
    sudo chmod -R 777 helloWorld
    cd helloWorld 
    ionic platform add android
    If you are still getting the error then remove ".cordova" folder from the home directory of your PC.

3. To run the app in your android emulator: ionic run android

3.在你的android模拟器中运行应用程序:离子运行android

Thanks!

谢谢!

#4


7  

For those having a portable SDK edition on windows, simply add the 2 following path to your system.

对于那些在Windows上具有便携式SDK版本的用户,只需将以下两个路径添加到您的系统即可。

F:\ADT_SDK\sdk\platforms
F:\ADT_SDK\sdk\platform-tools

This worked for me.

这对我有用。

#5


4  

I had this issue before.
You need to add sdks\tools and sdks\build-tools to your environment path.

我以前遇到过这个问题。您需要将sdks \ tools和sdks \ build-tools添加到环境路径中。

#6


1  

Came here from google looking for same issue and wasted 4 hours to figure out what could be wrong. And now I feel really stupid while posting this answer. In my case SDK, JDK, JRE, Ant and everything else was installed and working a day before.

从谷歌来到这里寻找同样的问题,浪费了4个小时来弄清楚可能出现的问题。现在,在发布这个答案时,我觉得非常愚蠢。在我的情况下,SDK,JDK,JRE,Ant和其他一切安装并在前一天工作。

But just one particular project was giving me this issue. This one was under "C:\Users\Name\Documents" location

但只有一个特定的项目给了我这个问题。这个位于“C:\ Users \ Name \ Documents”位置下

Soon I realized that I was running cmd as normal user, as soon as I choose "Run as Administrator" everything started working.

很快我意识到我正在以普通用户身份运行cmd,只要我选择“以管理员身份运行”,一切都开始工作了。

Tip: Always consider project location carefully!

提示:请务必仔细考虑项目位置!

#7


0  

I experienced this issue on windows7 computer: the computer shutdown while ionic serve was running (I'm assuming that was the issue that corrupted everything)

我在windows7计算机上遇到过这个问题:当离子服务器正在运行时计算机关闭(我假设这是破坏一切的问题)

Remove node COMPLETELY and reinstall everything on a fresh node copy

完全删除节点并在新节点副本上重新安装所有内容

#1


118  

You may want to confirm that your development environment has been set correctly.

您可能需要确认已正确设置开发环境。

Quoting from spring.io:

引自spring.io:

Set up the Android development environment

Before you can build Android applications, you must install the Android SDK. Installing the Android SDK also installs the AVD Manager, a graphical user interface for creating and managing Android Virtual Devices (AVDs).

在构建Android应用程序之前,必须先安装Android SDK。安装Android SDK还会安装AVD Manager,这是一个用于创建和管理Android虚拟设备(AVD)的图形用户界面。

  1. From the Android web site, download the correct version of the Android SDK for your operating system.

    在Android网站上,为您的操作系统下载正确版本的Android SDK。

  2. Unzip the archive to a location of your choosing. For example, on Linux or Mac, you can place it in the root of your user directory. See the Android Developers web site for additional installation details.

    将存档解压缩到您选择的位置。例如,在Linux或Mac上,您可以将其放在用户目录的根目录中。有关其他安装详细信息,请参阅Android开发人员网站。

  3. Configure the ANDROID_HOME environment variable based on the location of the Android SDK. Additionally, consider adding ANDROID_HOME/tools, and ANDROID_HOME/platform-tools to your PATH.

    根据Android SDK的位置配置ANDROID_HOME环境变量。另外,请考虑在PATH中添加ANDROID_HOME / tools和ANDROID_HOME / platform-tools。

Mac OS X

export ANDROID_HOME=/<installation location>/android-sdk-macosx
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Linux

export ANDROID_HOME=/<installation location>/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

Windows

set ANDROID_HOME=C:\<installation location>\android-sdk-windows
set PATH=%PATH%;%ANDROID_HOME%\tools;%ANDROID_HOME%\platform-tools

The Android SDK download does not include specific Android platforms. To run the code in this guide, you need to download and install the latest SDK platform. You do this by using the Android SDK and AVD Manager that you installed in the previous section.

Android SDK下载不包含特定的Android平台。要运行本指南中的代码,您需要下载并安装最新的SDK平台。您可以使用上一节中安装的Android SDK和AVD Manager来完成此操作。

  1. Open the Android SDK Manager window:

    打开Android SDK Manager窗口:

    android
    

    Note: If this command does not open the Android SDK Manager, then your path is not configured correctly.

    注意:如果此命令未打开Android SDK Manager,则说明您的路径未正确配置。

  2. Select the Tools checkbox.

    选择“工具”复选框。

  3. Select the checkbox for the latest Android SDK.

    选中最新Android SDK的复选框。

  4. From the Extras folder, select the checkbox for the Android Support Library.

    在Extras文件夹中,选中Android Support Library的复选框。

  5. Click the Install packages... button to complete the download and installation.

    单击“安装包...”按钮以完成下载和安装。

    Note: You may want to install all the available updates, but be aware it will take longer, as each API level is a large download.

    注意:您可能希望安装所有可用的更新,但请注意它需要更长时间,因为每个API级别都是大型下载。

#2


25  

In Linux

在Linux中

First of all set ANDROID_HOME in .bashrc file

首先在.bashrc文件中设置ANDROID_HOME

Run command

运行命令

sudo gedit ~/.bashrc

set andoid sdk path where you have installed

设置已安装的andoid sdk路径

export ANDROID_HOME=/opt/android-sdk-linux 
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools

to reload file run command

重新加载文件运行命令

source ~/.bashrc

Now check installed platform, run command

现在检查已安装的平台,运行命令

ionic platform

Output

产量

Installed platforms:
  android 6.0.0
Available platforms: 
  amazon-fireos ~3.6.3 (deprecated)
  blackberry10 ~3.8.0
  browser ~4.1.0
  firefoxos ~3.6.3
  ubuntu ~4.3.4
  webos ~3.7.0

if android already installed then need to remove and install again

如果已安装android,则需要再次删除并安装

ionic platform rm android
ionic platform add android

If not installed already please add android platform

如果没有安装,请添加android平台

ionic platform add android

Please make sure you have added android platform without sudo command

请确保您已添加没有sudo命令的android平台

if you still getting error in adding android platfrom like following

如果你仍然在添加android platfrom时遇到错误,如下所示

Error: EACCES: permission denied, open '/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json'

错误:EACCES:权限被拒绝,打开'/home/ubuntu/.cordova/lib/npm_cache/cordova-android/6.0.0/package/package.json'

Please go to /home/ubuntu/ and remove .cordova folder from there

请转到/ home / ubuntu /并从那里删除.cordova文件夹

cd /home/ubuntu/
sudo rm -r .cordova

Now run following command again

现在再次运行以下命令

ionic platform add android

after adding platform successfully you will be able to build andoid in ionic.

成功添加平台后,您将能够在离子中构建andoid。

Thanks

谢谢

#3


18  

These are the steps that you need to follow to successfully set up your Ionic Project to work with android emulator:

以下是成功设置Ionic项目以使用Android模拟器时需要遵循的步骤:

  1. Create an Ionic Project: ionic start appName tabs (for tab theme)
  2. 创建一个离子项目:ionic start appName标签(用于标签主题)
  3. cd appName
  4. cd appName
  5. ionic setup sass
  6. 离子设置sass
  7. To start the app on web: ionic serve
  8. 在web上启动应用程序:ionic serve

To add android platform:

要添加android平台:

Priori Things

First you need to setup the environment variables. For this you need to consider 3 files:

首先,您需要设置环境变量。为此,您需要考虑3个文件:

1. ~/.profile (For setting up the variables every time terminal opens or computer boots up):

1.~ / .profile(每次终端打开或计算机启动时设置变量):

//Code that you need to append at the last

//你需要在最后添加的代码

set PATH so it includes user's private bin directories
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
export ANDROID_HOME='/home/<user_name>/Android/Sdk' <Path to android SDK>
export PATH=$PATH:$ANDROID_HOME/bin
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/platform-tools

2. /etc/environment (to set the environment variables):

2. / etc / environment(设置环境变量):

//All the content of the file

//文件的所有内容

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-oracle"
ANDROID_HOME="/home/<user_name>/Android/Sdk" <Path to android SDK>

3. /etc/profile:

3. / etc / profile:

//Code that you need to add at the last

//您需要在最后添加的代码

JAVA_HOME=/usr/lib/jvm/java-8-oracle <Path where Java is installed>
JRE_HOME=$JAVA_HOME/jre 
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH

For loading the above changes made to the file you need to run the following command:

要加载对文件所做的上述更改,您需要运行以下命令:

source ~/.profile
source /etc/environment
source /etc/profile

Posteori Things

1. Add platform: ionic platform add android (Note that you need to run this command without sudo)

1.添加平台:离子平台添加android(注意你需要在没有sudo的情况下运行此命令)

2. If you are still getting error in the above command then do the following: (here appName = helloWorld)

2.如果在上述命令中仍然出现错误,请执行以下操作:(此处appName = helloWorld)

    cd ..
    sudo chmod -R 777 helloWorld
    cd helloWorld 
    ionic platform add android
    If you are still getting the error then remove ".cordova" folder from the home directory of your PC.

3. To run the app in your android emulator: ionic run android

3.在你的android模拟器中运行应用程序:离子运行android

Thanks!

谢谢!

#4


7  

For those having a portable SDK edition on windows, simply add the 2 following path to your system.

对于那些在Windows上具有便携式SDK版本的用户,只需将以下两个路径添加到您的系统即可。

F:\ADT_SDK\sdk\platforms
F:\ADT_SDK\sdk\platform-tools

This worked for me.

这对我有用。

#5


4  

I had this issue before.
You need to add sdks\tools and sdks\build-tools to your environment path.

我以前遇到过这个问题。您需要将sdks \ tools和sdks \ build-tools添加到环境路径中。

#6


1  

Came here from google looking for same issue and wasted 4 hours to figure out what could be wrong. And now I feel really stupid while posting this answer. In my case SDK, JDK, JRE, Ant and everything else was installed and working a day before.

从谷歌来到这里寻找同样的问题,浪费了4个小时来弄清楚可能出现的问题。现在,在发布这个答案时,我觉得非常愚蠢。在我的情况下,SDK,JDK,JRE,Ant和其他一切安装并在前一天工作。

But just one particular project was giving me this issue. This one was under "C:\Users\Name\Documents" location

但只有一个特定的项目给了我这个问题。这个位于“C:\ Users \ Name \ Documents”位置下

Soon I realized that I was running cmd as normal user, as soon as I choose "Run as Administrator" everything started working.

很快我意识到我正在以普通用户身份运行cmd,只要我选择“以管理员身份运行”,一切都开始工作了。

Tip: Always consider project location carefully!

提示:请务必仔细考虑项目位置!

#7


0  

I experienced this issue on windows7 computer: the computer shutdown while ionic serve was running (I'm assuming that was the issue that corrupted everything)

我在windows7计算机上遇到过这个问题:当离子服务器正在运行时计算机关闭(我假设这是破坏一切的问题)

Remove node COMPLETELY and reinstall everything on a fresh node copy

完全删除节点并在新节点副本上重新安装所有内容