Meteor - 安装 android 平台找不到 ANDROID_HOME 变量

Posted

技术标签:

【中文标题】Meteor - 安装 android 平台找不到 ANDROID_HOME 变量【英文标题】:Meteor - Installing android platform cant find ANDROID_HOME variable 【发布时间】:2016-03-18 18:50:05 【问题描述】:

我在尝试安装安卓平台的时候报错环境变量android_HOME找不到,但是如果我echo它就证明它存在。

让我带你去吧:

1)让我们创建一个新应用

dbugger@mercury:~/projects/meteor$ meteor create test 
Created a new Meteor app in 'test'.           

To run your new app:                          
  cd test                                     
  meteor                                      

If you are new to Meteor, try some of the learning resources here:
  https://www.meteor.com/learn                

2) 到目前为止,一切顺利。现在让我们安装android平台

dbugger@mercury:~/projects/meteor$ cd test/

dbugger@mercury:~/projects/meteor/test$ meteor add-platform android --verbose
Writing new config.xml                        
Creating Cordova project                      
% Creating a new cordova project.             
Adding platform Android to Cordova project    
=> Errors executing Cordova commands:         

   While adding platform Android to Cordova project:
   Cordova error: CordovaError: Failed to fetch platform android
   Probably this is either a connection problem, or platform spec is incorrect.
   Check your connection and platform name/version/URL.
   undefined
   at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/cordova-lib/src/cordova/platform.js:270:25
   at _rejected (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:797:24)
   at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:823:30
   at Promise.when (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:1035:31)
   at Promise.promise.promiseDispatch (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:741:41)
   at /home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:557:44
   at flush (/home/dbugger/.meteor/packages/meteor-tool/.1.1.10.ki0ccv++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/lib/node_modules/q/q.js:108:17)
   at process._tickCallback (node.js:448:13)
   (If the error message contains suggestions for a fix, note that this may not apply to the Meteor integration. You can try running again with the --verbose option to help diagnose the issue.)

3) 好吧,结果不太好。让我们试试sudo

dbugger@mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose
Adding platform Android to Cordova project    
% Adding android project...                   
android: added platform                       
Checking Cordova requirements for platform Android

Your system does not yet seem to fulfill all requirements to build apps for Android.

Please follow the installation instructions here:
https://github.com/meteor/meteor/wiki/Mobile-Development-Install:-Android-on-Linux

Status of the requirements:                   
✓ Java JDK                                    
✗ Android SDK: 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.
✗ Android target: Android SDK not found. Make sure that it is installed. If it is not at the default location, set the ANDROID_HOME environment variable.
✗ Gradle: Could not find gradle wrapper within Android SDK. Could not find Android SDK directory.
  Might need to install Android SDK or set up 'ANDROID_HOME' env variable.

4)等等,什么?我确定设置了环境变量。让我们检查一下。

dbugger@mercury:~/projects/meteor/test$ echo $ANDROID_HOME
/home/dbugger/Android/Sdk

5) 我知道!那为什么失败了……?让我们再检查一遍

dbugger@mercury:~/projects/meteor/test$ sudo meteor add-platform android --verbose


While adding platforms:
error: android: platform is already added

什么?!现在事实证明它最终安装了?这里发生了什么?我怀疑我的系统中的某些东西配置错误,但我不确定是什么...

【问题讨论】:

我也有同样的问题,你解决了吗? 我还没解决... 我解决了它,但无法重现它以提供明确的答案,通常可以肯定 sudo 不应该在流星中使用,我必须为我的用户授予所有流星/项目的权限/android 文件夹。 【参考方案1】:

您正在使用sudo

    你可能不应该 即使ANDROID_HOME 变量是为您当前的用户定义的,并不意味着它也是为root 用户定义的,这就是sudo 调用的环境。

我真的建议不要将 sudo 用于流星。如果您可以避免这种情况,那么它应该可以工作并且您的问题已经解决。否则,请确保也为 root 用户定义 ANDROID_HOME 变量,或者只使用

sudo env ANDROID_HOME=[whatever you want it to be] meteor

改为。

【讨论】:

with sudo env 我没有收到那个错误...如果我需要设置多个环境变量怎么办? 我要回顾一下我的整个安装过程。可能我安装了一些我不应该安装的东西...... 修复您的安装可能需要做的就是在您的主目录和项目文件夹中的sudo chown -R USERNAME .meteor sudo chown -R USERNAME . 我认为 USERNAME 必须是我的系统用户名,在本例中为“dbugger”。可悲的是,这并没有解决我的问题。我仍然需要使用sudo env ... 检查所有项目文件和~/.meteor 中的所有者。它们都必须是你自己的。之后,您应该能够在没有sudo 的情况下启动流星。

以上是关于Meteor - 安装 android 平台找不到 ANDROID_HOME 变量的主要内容,如果未能解决你的问题,请参考以下文章

找不到模块'./..../x.html' - TsLint / Angular-Meteor

Android Studio 更新 0.5.3 - 找不到平台“android-19”

将流星部署到 android-device 时找不到 Build Tools 修订版 24.0.1

typescript在@types中找不到模块

找不到带有哈希字符串“android-P”的目标

Android ------ apk签名时出现找不到证书链