无法找到'ANDROID_HOME'环境变量。无法在'PATH'中找到'android'命令

时间:2016-01-19 22:15:51

标签: android cordova ubuntu

我正在尝试在我的ubuntu系统上为android构建默认的Hello World phonegap项目,但我在每一步都遇到错误。

简短版本:

  1. 我不能创建没有sudo的phonegap项目(不完全正确 - 见下文)。
  2. 用sudo创建一个phonegap项目后,我无法在没有sudo的情况下构建android。
  3. 当我输入“sudo phonegap build android”时,我丢失了路径设置,导致错误。
  4. 我试图修复这个最后一个问题,在{。{3}}中建议在in.bashrc中添加“alias sudo ='sudo env PATH = $ PATH'”这一行,但它不起作用。我还将ANDROID_HOME和PATH行添加到.bash_profile,但没有成功。
  5. 我认为'android'命令实际上就在我的路上。
  6. 以下是我.ba​​shrc的最后一行:

    export PATH="$HOME/Android/tools:$PATH"
    export PATH="$HOME/Android/platform-tools:$PATH"
    export ANDROID_HOME="$HOME/Android:$PATH"
    alias sudo='sudo env PATH=$PATH'
    

    我在〜/ .bash_profile中也有以下内容:

    export PATH="$HOME/Android/tools:$PATH"
    export PATH="$HOME/Android/platform-tools:$PATH"
    export ANDROID_HOME="$HOME/Android:$PATH"
    

    LONG VERSION:

    gregory@gregory-1001PXD:~/javascript$ phonegap create phonetest
    
    
    Error: EACCES, permission denied '/home/gregory/.config/configstore/update-notifier-cordova.json'
    You don't have access to this file.
    
        at Object.fs.openSync (fs.js:432:18)
        at Object.fs.readFileSync (fs.js:286:15)
        at Object.create.all.get (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:34:26)
        at Object.Configstore (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/node_modules/configstore/index.js:27:44)
        at new UpdateNotifier (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/index.js:34:17)
        at module.exports (/usr/local/lib/node_modules/phonegap/node_modules/cordova/node_modules/update-notifier/index.js:123:23)
        at checkForUpdates (/usr/local/lib/node_modules/phonegap/node_modules/cordova/src/cli.js:64:20)
        at cli (/usr/local/lib/node_modules/phonegap/node_modules/cordova/src/cli.js:114:5)
        at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/node_modules/cordova/bin/cordova:41:1)
        at Module._compile (module.js:456:26)
    
    
    gregory@gregory-1001PXD:~/javascript$ sudo phonegap create phonetest
    [sudo] password for gregory: 
    Creating a new cordova project.
    gregory@gregory-1001PXD:~/javascript$ cd phonetest/
    gregory@gregory-1001PXD:~/javascript/phonetest$ sudo phonegap build android
    [phonegap] executing 'cordova build android'...
    cp: no such file or directory: /home/gregory/javascript/phonetest/icon.png
    
    
    Running command: /home/gregory/javascript/phonetest/platforms/android/cordova/build 
    
    [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.]
    
    ERROR building one of the platforms: Error: /home/gregory/javascript/phonetest/platforms/android/cordova/build: Command failed with exit code 2
    You may not have the required environment or OS to build this project
    
    Error: /home/gregory/javascript/phonetest/platforms/android/cordova/build: Command failed with exit code 2
    

    我认为android命令在我的PATH中(它是tab-complete)。

    注意:如果我删除文件update-notifier-cordova.json,我可以创建一个没有sudo的项目。但它仍会产生错误,如下所示。

    gregory@gregory-1001PXD:~/javascript$ sudo mv /home/gregory/.config/configstore/update-notifier-cordova.json ~/Documents/
    gregory@gregory-1001PXD:~/javascript$ phonegap create phonetest
    Creating a new cordova project.
    
    gregory@gregory-1001PXD:~/javascript$ cd phonetest/
    gregory@gregory-1001PXD:~/javascript/phonetest$ phonegap build android
    [phonegap] executing 'cordova platform add --save android'...
    Error: Failed to fetch platform android@~4.1.0
    Probably this is either a connection problem, or platform spec is incorrect.
    Check your connection and platform name/version/URL.
    Error: EACCES, open '/home/gregory/.cordova/lib/npm_cache/cordova-android/4.1.1/package/.npmignore'
    
    [phonegap] executing 'cordova build android'...
    Error: No platforms added to this project. Please use `cordova platform add <platform>`.
    

1 个答案:

答案 0 :(得分:0)

这在他们的JIRA中有记载:https://issues.apache.org/jira/browse/CB-10062

使用以下方法检查文件的所有权:

ls -al /home/gregory/.config/configstore/update-notifier-cordova.json

如果是root用户,您可能需要尝试重新安装cordova - 否则请使用运行建议的解决方法:

chmod 744 /home/gregory/.config/configstore/update-notifier-cordova.json