1. 程式人生 > >蘋果mac系統下cocos2d android和ios含NDK開發環境搭建 安裝說明20161129

蘋果mac系統下cocos2d android和ios含NDK開發環境搭建 安裝說明20161129


mac系統上搭建android cocos2d環境 包括NDK等


一、工具
不能用中文路徑或放在中文路徑下
1.這不用下載:android sdk映象 https://dsx.bugly.qq.com/repository/1 更新android sdk 4.4.2
2.ADT  連結: http://pan.baidu.com/s/1c2qcGQ8 密碼: tvum
3.android NDK 連結: http://pan.baidu.com/s/1byEaaq 密碼: nuep
4.apache-ant-1.9.7-bin.zip   http://apache.fayea.com//ant/binaries/apache-ant-1.10.1-bin.zip
5.python-2.7.11 https://www.python.org/ftp/python/2.7.11/python-2.7.11-macosx10.6.pkg
6.cocos2d  http://www.cocos.com/download
7. Java for OS X 2015-001  https://support.apple.com/kb/DL1572?locale=zh_CN
9.JAVA 連結: http://pan.baidu.com/s/1hr8BllE 密碼: 4ja2


Mac 下解壓NDK .bin檔案,轉到目錄下cd /Users/Dream/Documents/cocos
1.獲取檔案許可權
chmod a+x android-ndk-r10e-darwin-x86_64.bin
2. 解壓出檔案
./android-ndk-r10e-darwin-x86_64.bin


二、環境安裝
1.安裝Python 2.7.5 或者更高版本。開啟終端並輸入命令python。


如果已經安裝了的話,會有下面的資訊出來:
====================================================================


Python 2.7.6 (default, Sep  9 2014, 15:04:36) 


[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.39)] on darwin


Type "help", "copyright", "credits" or "license" for more information.


====================================================================
注:查完Python的版本後,你可以跑exit()退出Python


2.首先開啟終端並定位到Cocos2dx所在的目錄,如:cd /Users/Dream/Documents/cocos2d-x-3.6   跑一下命令./setup.py會提示你設定變數。


/Users/wangchao/Desktop/cocos/android-ndk-r10e
/Users/wangchao/Desktop/cocos/adt-bundle-mac-x86_64-20140702/sdk
/Users/wangchao/Desktop/cocos/apache-ant-1.9.7/bin


設定好後,終端的末尾會有一條訊息:


====================================================================


Please execute command: "source /Users/Dream/.bash_profile" to make added system variables take effect


====================================================================
如果執行後source /Users/wangchao/.bash_profile提示not a valid identifier 則


vi ~/.bash_profile
:wq 儲存退出
就可以了。




3.建立專案  cocos new ColorBird -p com.evanlin.colorbird -l cpp -d "/Users/wangchao/test" 




4.編譯專案 cd /Users/wangchao/test/ColorBird/proj.android
cocos compile -p Android --ap android-19




mac系統上搭建IOS cocos2d環境 


用上面的步驟建立好專案以後,開啟專案目錄,你可以看到資料夾proj.ios_mac。進入這個資料夾後,你可以看到XCode的專案檔案。雙擊開啟它就可以跑了。


另外,如果ios 編譯出錯的解決


位置計算文字高寬


* BUILD FAILED **




The following build commands failed:
CompileC build/cocos2d_libs.build/Debug-iphonesimulator/libcocos2d\ iOS.build/Objects-normal/i386/CCDevice-ios.o /Users/wangchao/test/ColorBird/cocos2d/cocos/platform/ios/CCDevice-ios.mm normal i386 objective-c++ com.apple.compilers.llvm.clang.1_0.compiler
(1 failure)
編譯失敗:請從上面的輸出中檢視錯誤細節。
bogon:proj.ios_mac wangchao$ 
bogon:proj.ios_mac wangchao$ 


cannot initialize a parameter of type 'NSStringDrawingOptions' with an rvalue of type 'long'


相關語句,註釋掉就行了。 














附(不用設定):


1.配置mac下的環境變數
開啟終端配置環境變數,輸入以下命令:vim ~/.bash_profile


按鍵i,進行插入編輯(如果輸錯d進行刪除一行)


修改以下路徑:
export PATH=$PATH:/Users/yourmacname/adtformac/sdk/tools?
export PATH=$PATH:/Users/yourmacname/adtformac/sdk/platform-tools?
export PATH=$PATH:/Users/yourmacname/android-ndk-r9b/?
export ANDROID_NDK_ROOT=/Users/yourmacname/android-ndk-r9b/?
export ANDROID_SDK_ROOT=/Users/yourmacname/adtformac/sdk?
export NDK_ROOT=/Users/yourmacname/android-ndk-r9b/
複製進去


按esc,再命令輸入命令:


:wq




2.在adt 設定 android ndk 加入NDK路徑E:\soft\android-ndk-r10d 在cocos示例中複製一份build_native.py到新建的專案中,就可以用eclipse直接編譯了。