android - Cordova 错误 : Failed to find 'ANDROID_HOME' environment variable

标签 android linux jenkins build automation

我已经在 bash_profile 中为我的 jenkins 用户设置了 $ANDROID_HOME$PATH(在我的例子中是管理员用户),我可以看到 env 当我这样做时 var 获取值

echo $ANDROID_HOME 
echo $PATH

但是当我这样做的时候

sudo cordova build android

它给了我错误

CordovaError: Failed to find 'ANDROID_HOME' environment variable.Try setting it manually. Try update your 'PATH'

知道为什么以及如何修复它吗?

最佳答案

当您使用 sudo 运行命令时,该命令不会从父(非特权)shell 继承环境变量。出于安全原因。

解决方案:

  • 使用 sudo bash 启动 root shell。然后设置环境变量并在 root shell 中运行构建命令。

  • 使用 sudo -E ...sudo --preserve-env=... 但请阅读手册条目,因为这是有风险的。

  • 不要尝试以 root 身份运行 cordova。 (你为什么这样做?这似乎有风险。你能确定你的构建没有错误,如果以 root 身份运行可能会损坏你的系统吗?你能相信构建“脚本”的来源吗?)

关于android - Cordova 错误 : Failed to find 'ANDROID_HOME' environment variable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49030143/

相关文章:

python - pip install --find-links html文件格式

java - 尝试构建类似视频中的东西

linux - 如何解释 fio iops 日志文件?

python - 什么条件导致打开的非阻塞命名管道 (fifo) 为 "unavailable"用于读取?

jenkins - 如何访问groovy类文件中的全局变量?

xamarin - 在 Jenkins 上运行 NUnit 测试的问题

android - Google maps android api 使用哪个证书?

android - 与所有 Activity 共享 NavigationView?

android - 如何调整TextView中文本的大小?

在 Linux EC2 实例中使用 sudo pip3 install python-binance 时 python-binance 无法编译错误