Error: Failed to find 'ANDROID_HOME' environment variable when building apk using ionic

时间:2016-08-30 04:46:27

标签: android linux ionic-framework

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

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 ) .

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

export ANDROID_HOME=/home/ttnd/android-sdk-linux
export PATH=${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 个答案:

答案 0 :(得分:3)

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

您可以通过向sudo命令添加-E选项来解决此问题。使用该选项可能存在一些安全问题,您的特定系统可能会阻止您使用该选项。这是我的sudo手册页版本的简介:

  

-E(保留环境)选项指示用户希望的安全策略                      保留现有的环境变量。如果-E,安全策略可能会返回错误                      指定了选项,用户无权保留环境。

另一种方法是将环境变量包含在sudo命令中。像这样:

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

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