溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

ionic框架配置

發(fā)布時間:2020-07-25 19:56:07 來源:網(wǎng)絡(luò) 閱讀:659 作者:dingzhaoqiang 欄目:移動開發(fā)

ionic簡介

ionic是一個專注于用WEB開發(fā)技術(shù),基于HTML5創(chuàng)建類似于手機(jī)平臺原生應(yīng)用的一個開發(fā)框架。目前綁定的與angularJS和SASS。這個框架的目的是從web的角度開發(fā)手機(jī)應(yīng)用,基于PhoneGap的編譯平臺,可以實(shí)現(xiàn)編譯成各個平臺的應(yīng)用程序。

ionic安裝

首先需要安裝cordova和android環(huán)境。這個參考:phoneGap之Android環(huán)境搭建,上面寫的很詳細(xì),還有常見的錯誤及解決辦法。
然后安裝ionic:

npm install -g ionic

如果因?yàn)榫W(wǎng)絡(luò)原因安裝不上有兩種辦法:

1.修改npm源為淘寶npm源,可以使用下面三種方法中的任意一種

A.通過config命令

npm config set registry https://registry.npm.taobao.org 

npm info underscore (如果上面配置正確這個命令會有字符串response)

B.命令行指定

npm --registry https://registry.npm.taobao.org info underscore

C.編輯 ~/.npmrc 加入下面內(nèi)容

registry = https://registry.npm.taobao.org

2.拷貝安裝過的ionic目錄,配置環(huán)境變量或者建立軟連接。

安裝完成之后,就可以使用ionic創(chuàng)建項(xiàng)目了。

ionic start myApp tabs   //創(chuàng)建帶有top欄和bottom欄的示例項(xiàng)目

ionic start myApp sidemenu  //創(chuàng)建帶有左側(cè)帶有menu欄的示例項(xiàng)目

ionic start myApp blank   //創(chuàng)建空白項(xiàng)目

具體效果,可以查看官網(wǎng): http://ionicframework.com/getting-started/
然后可以使用:

ionic serve

該命令會自動啟動流瀏覽器,查看當(dāng)前效果。

添加Android平臺

執(zhí)行下面的命令,

cd myApp
ionic platform add android //這行可能會報錯
ionic build android
ionic emulate android

其實(shí)上面的使用方法和cordova差不多,添加android的時候可能會報錯,如下:

The error is: ======================================= events.js:72 throw er; // Unhandled 'error' event ^ Error: spawn ENOENT at errnoException (child_process.js:1000:11) at Process.ChildProcess._handle.onexit (child_process.js:791:34)

解決的方法很簡單,將ionic換成cordova即可,經(jīng)測試works fine。

cd myApp
cordova platform add android //這行可能會報錯
cordova build android
cordova emulate android

其他常見錯誤

  1. 生成項(xiàng)目(ionic start myApp tabs)時可能會報錯,如下:

Error: command failed:fatal:could not create work tree dir:'C:\Users/ADMINI~1\AppData\Local\Temp\plugman\git\1402853493773'.:No such file or directory

解決辦法:進(jìn)入上面對應(yīng)的目錄,建立對應(yīng)的文件。比如在temp目錄下建立plugman目錄,在plugman目錄下建立git目錄,然后再git下建立1402853493773目錄。即可,經(jīng)測試有效。

2.sh: 1: node-gyp: Permission denied 安裝軟件包報錯
這個一般是centos等系統(tǒng),在root用戶下安裝會報錯。主要是權(quán)限問題,報錯詳情:

> node-gyp rebuild

sh: 1: node-gyp: Permission denied
\
> ws@0.4.32 install /root/.nvm/versions/node/v0.12.4/lib/node_modules/log.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)


> ws@0.4.32 install /root/.nvm/versions/node/v0.12.4/lib/node_modules/log.io/node_modules/socket.io/node_modules/socket.io-client/node_modules/ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

npm ERR! Linux 3.13.0-48-generic
npm ERR! argv "/root/.nvm/versions/node/v0.12.4/bin/node" "/root/.nvm/versions/node/v0.12.4/bin/npm" "install" "-g" " log.io"
npm ERR! node v0.12.4
npm ERR! npm v2.10.1
npm ERR! file sh
npm ERR! code ELIFECYCLE
npm ERR! errno ENOENT
npm ERR! syscall spawn

npm ERR! contextify@0.1.14 install: `node-gyp rebuild`
npm ERR! spawn ENOENT
npm ERR!
npm ERR! Failed at the contextify@0.1.14 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the contextify package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! node-gyp rebuild
npm ERR! You can get their info via:
npm ERR! npm owner ls contextify
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR! /root/npm-debug.log

可以清楚看到訊息中提示我們在執(zhí)行node-gyp 的時候權(quán)限不足。

查詢一下Google ,找到別人blog寫得簡單解決方法:

npm config set unsafe-perm true

接下來安裝就正常了。 至于npm config的使用方法, 請參考 此處 .
我們可以從npm config set unsafe-perm的解說中看到,我們剛剛修改的意思。

Default: false if running as root, true otherwise
Type: Boolean
Set to true to suppress the UID/GID switching when running package scripts. If set explicitly to false, then installing as a non-root user will fail.


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI