Mac安装PhoneGap3第一步需要安装NodeJS,在Mac下有一个.pkg安装包(Mac OS X Installer (.pkg),下载下来一路点击就可以安装成功了。在Terminal控制台输入node -v就可以看到安装成功了。第二步是安装PhoneGap,打开Terminal控制台输入:
$ sudo npm install -g phonegap
安装好了以后输入创建第一个例子:
$ phonegap create my-app $ cd my-app $ phonegap run ios
结果报错:
[phonegap] detecting iOS SDK environment... [phonegap] using the local environment [phonegap] adding the iOS platform... [error] An error occured during creation of ios sub-project. /bin/sh: /Users/umk/.cordova/lib/ios/cordova/3.3.0/bin/create: No such file or directory
是因为PhoneGap用到Apache Cordova引擎,没有安装好,我国网络状况用Git的原因....只好手动下载一个Cordova,解压,然后把内容全部复制到/Users/umk/.cordova/lib/ios/cordova/3.3.0/,然后再运行命令:
$ cd my-app
$ phonegap run ios
结果报错:
[phonegap] compiling iOS... cp: copyFileSync: could not write to dest file (code=ENOENT):/Users/umk/my-app/platforms/ios/cordova/defaults.xml events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:988:11) at Process.ChildProcess._handle.onexit (child_process.js:779:34)
解决办法是重新创建一个例子:
$ phonegap create my-app2 $ cd my-app2 $ phonegap run ios
报错说下载ios-sim失败:
[phonegap] detecting iOS SDK environment... [phonegap] using the local environment [phonegap] adding the iOS platform... [phonegap] compiling iOS... [phonegap] successfully compiled iOS app [phonegap] trying to install app onto device [phonegap] no device was found [phonegap] trying to install app onto emulator [warning] missing ios-sim [warning] install ios-sim from http://github.com/phonegap/ios-sim [error] An error occurred while emulating/deploying the ios project. Error: ios-sim was not found. Please download, build and install version 1.7 or greater from https://github.com/phonegap/ios-sim into your path. Or 'npm install -g ios-sim' using node.js: http://nodejs.org/
这个好办,下载ios-sim就可以了:
$ sudo npm install -g ios-sim
再次运行成功,看到iPhone模拟器起来了:
[phonegap] detecting iOS SDK environment... [phonegap] using the local environment [phonegap] compiling iOS... [phonegap] successfully compiled iOS app [phonegap] trying to install app onto device [phonegap] no device was found [phonegap] trying to install app onto emulator [phonegap] successfully installed onto emulator
这样,my-app项目platforms/ios文件夹下会有xcode的porject,双击就可以用xcode打开。
附录:我的版本情况
$ phonegap -v 3.3.0-0.19.6 $ node -v v0.10.26 $ git --version git version 1.8.3.4 (Apple Git-47) $ cordova -v 3.4.0-0.1.2