1 配置基本的java環境
2 安裝Node.js 直接在官網(http://nodejs.org/)下載node-v0.10.35.pkg文件
一直下一步安裝,安裝完成後顯示Node was installed at
/usr/local/bin/node
npm was installed at
/usr/local/bin/npm
Make sure that /usr/local/bin is in your $PATH.
可以看出同時也安裝好了npm
3 安裝git client(http://www.git-scm.com/downloads)
Step 1 - Install Package
------------------------
Double-click the package in this disk image to install. This installs
git to /usr/local/git. Root access is required.
Step 2 - Restart bash sessions
------------------------------
This include GNU screen sessions, TMUX sessions, etc. If you wish to preserve your precious screen session, just `source /etc/profile` and yo
Step 3 - Run shell script
-------------------------
This step is optional.
Non-terminal programs don't inherit the system wide PATH and MANPATH
variables that your terminal does. If you'd like them to be able to
see Git, for whatever reason, you can run this script. It will add the
PATH and MANPATH to your ~/.MacOSX/environment.plist file. You'll need
to log out of your user account for that to take effect.
4 下載安裝crodova
在終端 $ sudo npm install -g cordova
5 創建app
終端進入想存放的目錄下,$ cordova create hello com.example.hello HelloWorld
此時相應建立了目錄(圖1)
6 進入工程目錄(cd helllo),添加需要的開發平臺
cordova platform add ios
(添加android平臺的時候出錯)
HongChunHuadeMacBook-Pro:hello hongchunhua$ cordova platform add android
/Users/hongchunhua/.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 /Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/lib/check_reqs.js:159:19
at _fulfilled (/Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:798:54)
at self.promiseDispatch.done (/Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:827:30)
at Promise.promise.promiseDispatch (/Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:760:13)
at /Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:821:14
at flush (/Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/node_modules/q/q.js:108:17)
at process._tickCallback (node.js:442:13)
at Function.Module.runMain (module.js:499:11)
at startup (node.js:119:16)
at node.js:929:3
Error: /Users/hongchunhua/.cordova/lib/npm_cache/cordova-android/3.6.4/package/bin/create: Command failed with exit code 8
at ChildProcess.whenDone (/usr/local/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:766:16)
at Process.ChildProcess._handle.onexit (child_process.js:833:5)
//解決方法
1. 啓動終端Terminal
2. 進入當前用戶的home目錄
輸入cd ~
3. 創建.bash_profile
輸入touch .bash_profile
4. 編輯.bash_profile文件
輸入open -e .bash_profile
因爲是爲了搭建Android開發環境,輸入Android SDK下的tools目錄:export PATH=${PATH}:/eclipse/android_sdk/tools
5. 保存文件,關閉.bash_profile
6. 更新剛配置的環境變量
輸入source .bash_profile
7. 驗證配置是否成功
輸入android啓動Android SDK and AVD Manager
(
在/etc/profile 裏添加PATH 和 ANDROID_HOME環境變量後,問題依然。
google 一把,發現也有人遭遇這個詭異的狀況,沒有人有辦法解決。
最後受其中一篇回覆的啓發(其中提到要確保對sdk目錄有寫權限),把adt的sdk目錄放到當前用戶的~目錄下,並且修改了權限:
chmod -R 777 sdk/
)
//解決之後,成功生成
HongChunHuadeMacBook-Pro:hello hongchunhua$ cordova platform add android
Creating android project...
Creating Cordova project for the Android platform:
Path: platforms/android
Package: com.example.hello
Name: HelloWorld
Android target: android-19
Copying template files...
Project successfully created.
7 顯示所支持的平臺(cordova platforms ls)