错误:使用ionic构建apk时未能找到“ANDROID_HOME”环境变量。

时间:2021-06-06 23:11:58

I am trying to build android apk using ionic framework. When I enter the following command sudo ionic build android , I get the following error "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. " .

我正在尝试使用ionic框架构建android apk。当我输入以下命令sudo ionic build android时,我得到以下错误“error: Failed to find 'ANDROID_HOME”环境变量。尝试手动设置。在“路径”中找不到“android”命令。尝试更新“路径”以包含到有效SDK目录的路径。”。

But when I check ANDROID_HOME variable by typing "echo $ANDROID_HOME" , I get the valid SDK path( e.g. /home/ttnd/android-sdk-linux ) .

但是当我通过键入“echo $ANDROID_HOME”来检查ANDROID_HOME变量时,我得到了有效的SDK路径(例如/home/ttnd/android-sdk-linux)。

Find below the configuration that I have included in the bashrc file ,

在bashrc文件中包含的配置下面找到,

export ANDROID_HOME=/home/ttnd/android-sdk-linux
export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools
.

导出ANDROID_HOME=/home/ttnd/android-sdk-linux导出路径=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools。

I have checked all the possible links available on web but still I am unable to find the issue.

我已经检查了网上所有可能的链接,但我仍然无法找到问题。

1 个解决方案

#1


3  

The problem is that the execution environment for the sudo command is different than the calling one. In other words, your environment variables don't get passed in.

问题是sudo命令的执行环境与调用命令的执行环境不同。换句话说,您的环境变量不会传入。

You may be able to fix that by adding the -E option to the sudo command. There are some possible security concerns with using that option and your particular system may block you from using it. Here's a blurb from my version of the sudo man page:

您可以通过向sudo命令添加-E选项来修复这个问题。使用该选项可能存在一些安全问题,您的特定系统可能会阻止您使用该选项。下面是我的sudo man页面的简介:

The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.

-E (save environment)选项向安全策略表明,用户希望保留现有的环境变量。如果指定了-E选项,并且用户没有权限保存环境,那么安全策略可能会返回一个错误。

Another way around it would be to to include the environment variables as part of the sudo command. Something like this:

另一种方法是将环境变量包括作为sudo命令的一部分。是这样的:

sudo ANDROID_HOME=$ANDROID_HOME PATH=$PATH ionic build android

A third way would be to run the sudo visudo and add the variables that you'd like to be included in the sudo run environment.

第三种方法是运行sudo visudo并添加希望包含在sudo运行环境中的变量。

#1


3  

The problem is that the execution environment for the sudo command is different than the calling one. In other words, your environment variables don't get passed in.

问题是sudo命令的执行环境与调用命令的执行环境不同。换句话说,您的环境变量不会传入。

You may be able to fix that by adding the -E option to the sudo command. There are some possible security concerns with using that option and your particular system may block you from using it. Here's a blurb from my version of the sudo man page:

您可以通过向sudo命令添加-E选项来修复这个问题。使用该选项可能存在一些安全问题,您的特定系统可能会阻止您使用该选项。下面是我的sudo man页面的简介:

The -E (preserve environment) option indicates to the security policy that the user wishes to preserve their existing environment variables. The security policy may return an error if the -E option is specified and the user does not have permission to preserve the environment.

-E (save environment)选项向安全策略表明,用户希望保留现有的环境变量。如果指定了-E选项,并且用户没有权限保存环境,那么安全策略可能会返回一个错误。

Another way around it would be to to include the environment variables as part of the sudo command. Something like this:

另一种方法是将环境变量包括作为sudo命令的一部分。是这样的:

sudo ANDROID_HOME=$ANDROID_HOME PATH=$PATH ionic build android

A third way would be to run the sudo visudo and add the variables that you'd like to be included in the sudo run environment.

第三种方法是运行sudo visudo并添加希望包含在sudo运行环境中的变量。