cordova安装与配置
参数说明:
- cordova需要node安装,使用Safari打开nodejs.org,下载并安装 在终端输入node -v命令查看是否安装成功,出现版本号就代表安装成功了.
- 安装完成后需要从终端下载cordova,输入下面的命令就可以安装完成cordova :命令为: sudo npm install -g cordova
- 在终端使用 cordova -v 会出现以下错误
/usr/local/lib/node_modules/cordova/node_modules/insight/node_modules/configstore/index.js:53
throw err;
^
Error: EACCES: permission denied, open '/Users/zhekexinxi/.config/configstore/insight-cordova.json'
You don't have access to this file.
at Object.fs.openSync (fs.js:646:18)
at Object.fs.readFileSync (fs.js:551:33)
at Configstore.get (/usr/local/lib/node_modules/cordova/node_modules/insight/node_modules/configstore/index.js:34:26)
at new Configstore (/usr/local/lib/node_modules/cordova/node_modules/insight/node_modules/configstore/index.js:27:45)
at new Insight (/usr/local/lib/node_modules/cordova/node_modules/insight/lib/index.js:38:34)
at Object.<anonymous> (/usr/local/lib/node_modules/cordova/src/telemetry.js:26:15)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
zhekexinxideMac-mini:~ zhekexinxi$ touch helloworld.js
zhekexinxideMac-mini:~ zhekexinxi$ vim helloworld.js
zhekexinxideMac-mini:~ zhekexinxi$ node helloworld.js
Server running at http://127.0.0.1:1337/
^[:wq
exit
^C 上提示是权限够不,但是当你添加sudo之后,后续仍然其他的权限问题.当你依次添加sudo的执行后,生成的文件却没有权限打开.看来要换另外一个办法来解决了
解决方法:
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
-
新建项目
- 我们新建一个HelloWorld项目,在终端中输入
-
cordova create hello com.example.hello HelloWorld
名称 | 必填 | 描述 |
---|---|---|
hello | 必填 | 工程的文件夹名,会创建一个同名文件夹 |
com.example.hello | 可选 | 应用程序的id名,与Xcode中类似,可以在 config.xml 中修改,如果不指定的话默认为 io.cordova.hellocordova |
HelloWorld | 可选 | App的名称,也可在 config.xml 中修改 |
- 通过上面的命令会创建一个HelloWorld的文件夹,在终端中输入以下命令添加ios开发
-
cd HelloWorld cordova platform add ios
运行项目
8. 一种方法是在终端输入命令
- 一种方法是在终端输入命令 cordova run ios
- 另外一种方法是在Xcode中打开HelloWorld项目并点▶️键