原文:http://blog.csdn.net/likendsl/article/details/34617725
打開用戶目錄下.bash_profile文件,配置環境
- vim ~/.bash_profile //按鍵i,進行插入編輯(如果輸錯d進行刪除一行)
環境配置步驟如下:
1、首先配置下android sdk,我的是在opt目錄下
- #sdk
- export ANDROID_SDK_ROOT=/opt/android-sdk-macosx
- export PATH=$PATH:$ANDROID_SDK_ROOT
- export PATH=$PATH:$ANDROID_SDK_ROOT/platform-tools
2、ndk
- #ndk
- export NDK_ROOT=/opt/android-ndk-r9b
- export PATH=$PATH:$NDK_ROOT
3、ant
- #ant
- export ANT_ROOT=/opt/apache-ant-1.9.3/bin
- export PATH=$PATH:$ANT_ROOT
等一切都配置好之後,我們現在就應該到終端下cocos2d-x3.0的目錄下執行以下命令:
- ./setup.py
執行過之後終端會顯示以下內容
- ???mcbookpro:cocos2d-x-3.0$ ./setup.py
- Setting up cocos2d-x...
- ->Check environment variable COCOS_CONSOLE_ROOT
- ->Find environment variable COCOS_CONSOLE_ROOT...
- ->COCOS_CONSOLE_ROOT is found : /Project/cocos2d-x-3.0/tools/cocos2d-console/bin
- ->Configuration for Android platform only, you can also skip and manually edit "/Users/你的用戶名/.bash_profile"
- ->Check environment variable NDK_ROOT
- ->Find environment variable NDK_ROOT...
- ->NDK_ROOT is found : /opt/android-ndk-r9b
- ->Check environment variable ANDROID_SDK_ROOT
- ->Find environment variable ANDROID_SDK_ROOT...
- ->ANDROID_SDK_ROOT is found : /opt/android-sdk-macosx
- ->Check environment variable ANT_ROOT
- ->Find environment variable ANT_ROOT...
- ->ANT_ROOT is found : /opt/apache-ant-1.9.3/bin
- Please execute command: "source /Users/你的用戶名/.bash_profile" to make added system variables take effect
如果出現以上內容我們的配置就成功了,你到你的 /Users/你的用戶名/.bash_profile文件中看一下,會默認爲我們添加以下兩行代碼
- # Add environment variable COCOS_CONSOLE_ROOT for cocos2d-x
- export COCOS_CONSOLE_ROOT=/Project/cocos2d-x-3.0/tools/cocos2d-console/bin
- export PATH=$COCOS_CONSOLE_ROOT:$PATH
這時候你再重啓或執行以下代碼:
- source /Users/你的用戶名/.bash_profile
執行完成後沒有任何提示,沒關係,linux下沒有消息,就是好消息。
完成以上之後,你在終端下敲以cocos new 命令,你會驚奇的發現
- mcbookpro:cocos2d-x-3.0$ cocos new
- Runing command: new
- usage: cocos new [-h] [-p PACKAGE_NAME] -l {cpp,lua,js} [-d DIRECTORY]
- [-t TEMPLATE_NAME] [--no-native]
- [PROJECT_NAME]
- cocos new: error: argument -l/--language is required
- cocos new WXYCocosTemplate -p com.game.study -l cpp -d /Users/more2010wei/Documents/more2010wei/cocos2dproj/
- WXYCocosTemplate//工程名
- -p 後跟你的包名
- -l cpp 這是一個cpp工程
- -d 後跟的是你要建的工程路徑
命令執行完之後終端下出現:
- Runing command: new
- > Copy template into /Users/more2010wei/Documents/more2010wei/cocos2dproj/WXYCocosTemplate
- > Copying cocos2d-x files...
- > Rename project name from 'HelloCpp' to 'WXYCocosTemplate1'
- > Replace the project name from 'HelloCpp' to 'WXYCocosTemplate1'
- > Replace the project package name from 'org.cocos2dx.hellocpp' to 'com.game.study'
配置到現在就完成了,開始享受遊戲開發的樂趣吧。