2013-11-26 55 views
0

我已經構建了一個Phonegap應用程序,現在正試圖將它與Phonegap Build集成。我遵循非常簡單的指南here無法從命令行構建Phonegap項目

所以我做:

sudo npm install -g phonegap 
sudo phonegap create hello com.example.hello HelloWorld 
cd hello 

sudo phonegap local build android 

最後的命令導致錯誤:

The command `android` failed. Make sure you have the latest Android SDK installed, and the `android` command (inside the tools/ folder) added to your path. Output: /bin/sh: 1: android: not found 

我那麼做:

which android 

與結果:

/home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android 

這是一條路徑。

phonegap版本是3.1.0-0.15.0。

任何想法,爲什麼我得到這個錯誤?

編輯 如果我運行:

sudo phonegap local build /home/mark/Development/adt-bundle-linux-x86_64-20130522/sdk/tools/android 

我得到另一個錯誤:

/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141 
    platformPath = path.join('.', 'platforms', platform.local); 
                ^
TypeError: Cannot read property 'local' of undefined 
at LocalBuildCommand.module.exports.addPlatform (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:141:60) 
at LocalBuildCommand.execute (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:95:32) 
at LocalBuildCommand.run (/usr/local/lib/node_modules/phonegap/lib/phonegap/local.build.js:70:10) 
at Object.build (/usr/local/lib/node_modules/phonegap/lib/phonegap/util/command.js:28:25) 
at CLI.module.exports (/usr/local/lib/node_modules/phonegap/lib/cli/local.build.js:34:20) 
at CLI.module.exports [as argv] (/usr/local/lib/node_modules/phonegap/lib/cli/argv.js:66:17) 
at Object.<anonymous> (/usr/local/lib/node_modules/phonegap/bin/phonegap.js:24:21) 
at Module._compile (module.js:449:26) 
at Object.Module._extensions..js (module.js:467:10) 
at Module.load (module.js:349:32) 
+0

當您在命令行中輸入「android」時會得到什麼? – Purus

+0

它帶來了android sdk管理器... – user1716672

+0

是Ant安裝和配置的嗎? – Purus

回答

0

使用sudo安裝PhoneGap的NPM全局包,它的確定。 但你應該用自己的用戶

sudo npm install -g phonegap 
phonegap create hello com.example.hello HelloWorld 
phonegap local build android 

使用sudo執行您切換到root用戶運行的PhoneGap因此環境變量$ PATH不一定相同。

+0

這工作,謝謝! – user1716672

0

嘗試將Android路徑添加到您的PATH環境變量。

如果你使用Linux,第一次嘗試:

echo $PATH 

此命令來顯示PATH變量,搜索這個Android的路徑。 如果您沒有看到android路徑,則需要在環境變量上添加該路徑。 試試這個:

echo 'export PATH=$PATH:/home/user/mis_prog' >> /home/user/.bashrc 

你必須編輯你的登錄shell的配置文件。 通常BASH shell是最常用的,你必須編輯你的/home/user/.bashrc。

爲此,您將使用文本編輯器或僅使用命令使任務更輕鬆。

如果你使用一些Windows版本,你可以從伊迪絲系統propertyes,像這樣的環境變量PATH:http://www.computerhope.com/issues/ch000549.htm

+0

android路徑已經到PATH。當我從任何地方運行「android」時,它會打開SDK管理器.. – user1716672

1

懶散的android sdk版本將adb移動到平臺工具。嘗試在你的路徑中包含工具和平臺工具。請參閱

~/Tools/adt-bundle-linux-x86_64-20131030/sdk $ cat tools/adb_has_moved.txt
The adb tool has moved to platform-tools/

If you don't see this directory in your SDK, launch the SDK and AVD Manager (execute the android tool) and install "Android SDK Platform-tools"

Please also update your PATH environment variable to include the platform-tools/ directory, so you can execute adb from any location.

我使用以下導出命令。

export ANDROID_BUNDLE_HOME="$ATILLA_TOOLS/adt-bundle-linux-x86_64-20131030" 
export ANDROID_SDK_HOME="$ANDROID_BUNDLE_HOME/sdk" 
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games 

export PATH=$PATH:$ANDROID_SDK_HOME/tools 
export PATH=$PATH:$ANDROID_SDK_HOME/platform-tools 

adb和android都應該在命令行中工作。也嘗試使用

phonegap local build android 

沒有sudo。

看下面的例子

$phonegap create deneme1 
[phonegap] created project at /home/atilla/Projects/Denemeler/a/deneme1 
$cd deneme1/ 
$phonegap local build android 
[phonegap] adding the Android platform... 
[phonegap] compiling 
Android... [phonegap] successfully compiled Android app 

在此之後成功消息試圖找到你的平臺和apk文件。

$ls -al platforms/ 
$ls -al platforms/android/ 
$ls -al platforms/android/bin 

你應該在這個目錄中看到HelloWorld-debug.apk。

-rw-r--r-- 1 atilla atilla 1542462 Ara 5 14:31 HelloWorld-debug.apk