2014-10-29 63 views
2

我在Ubuntu 14.04安裝Phonegap通過使用這些命令:安裝科爾多瓦並加入平臺

$ sudo npm install -g phonegap 

然後,我通過使用這些命令安裝科爾多瓦:

$ sudo npm install -g cordova 

輸出是:

npm WARN engine [email protected]: wanted: {"node":">=0.6","npm":"1"} (current: {"node":"0.10.33","npm":"2.1.5"}) 
/usr/bin/cordova -> /usr/lib/node_modules/cordova/bin/cordova 
[email protected] /usr/lib/node_modules/cordova 
├── [email protected] 
├── [email protected] 
├── [email protected] ([email protected]) 
└── [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]) 

我使用這個命令創建了一個簡單的項目:

$ cordova create hello com.example.hello HelloWorld 

產量爲:

Creating a new cordova project with name "HelloWorld" and id "com.ajay.hello" at location "/home/ajay/hello" 
Downloading cordova library for www... 
Download complete 

然後我用$ cd hello生成的路徑到項目中。
後來我加入Android平臺:

$ cordova platform add android 

這是錯誤:

npm http GET https://registry.npmjs.org/cordova-android/3.6.4 
npm http 200 https://registry.npmjs.org/cordova-android/3.6.4 
npm http GET https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.4.tgz 
npm http 200 https://registry.npmjs.org/cordova-android/-/cordova-android-3.6.4.tgz 
Creating android project... 

/home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:126 
        throw e; 
         ^
Error: ANDROID_HOME is not set and "android" command not in your PATH. You must fulfill at least one of these conditions. 
    at /home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib/check_reqs.js:159:19 
    at _fulfilled (/home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:798:54) 
    at self.promiseDispatch.done (/home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:827:30) 
    at Promise.promise.promiseDispatch (/home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:760:13) 
    at /home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:821:14 
    at flush (/home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:108:17) 
    at process._tickCallback (node.js:419:13) 
    at Function.Module.runMain (module.js:499:11) 
    at startup (node.js:119:16) 
    at node.js:906:3 
Error: /home/ajay/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/create: Command failed with exit code 8 
    at ChildProcess.whenDone (/usr/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:135:23) 
    at ChildProcess.emit (events.js:98:17) 
    at maybeClose (child_process.js:756:16) 
    at Process.ChildProcess._handle.onexit (child_process.js:823:5) 

如何設置ANDROID_HOME?任何線索?

回答

2

您可以通過添加這些設置的ANDROID_HOME你.bashrc

ANDROID_HOME=/home/user/android-sdk-linux 
export ANDROID_HOME=$ANDROID_HOME 
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/ 

PATH=$PATH:$ANDROID_HOME/tools 
PATH=$PATH:$ANDROID_HOME/platform-tools 
PATH=$PATH:$ANDROID_HOME/build-tools 

也許你就必須改變一些值,以匹配您的配置。

您將需要輸入您的.bashrc文件或關閉終端窗口並重新打開它。

還看到:Ant failed to build on Ubuntu

+0

有關,如果你使用的是Mac什麼?我犯了同樣的錯誤。 – 2014-12-04 12:35:53

0

你需要設置你的Android SDK,Android SDK工具&的Android SDK平臺工具的路徑。

This將解決您的問題。

0

我只是在Mac OSX約塞米蒂10.10.3

運行sudo uninstall cordova然後sudo install cordova然後cordova platform add android,我希望這有助於:)