Mac Configuration cocos2d-x development environment (android and ios)

First, download the cocos2d-x

http://cocos2d-x.org/projects/cocos2d-x/wiki/Download

cocos2d-x-2.1.4.zip @ June.18, 2013

We can see the latest version 2.1.4, this version provides a project with python command to create each platform is very convenient

Download, extract (unzip recommend to your home directory)

 

Second, download python

http://www.python.org/getit/

Recommended to choose the version 2.7.5 download

Python 2.7.5 Mac OS X 64-bit/32-bit x86-64/i386 Installer
Python 2.7.5 Mac OS X 32-bit i386/PPC Installer

Download, install, and then enter the python directly in the terminal, the version information appears if the installation was successful.

 

Third, the establishment cocos2d-x project

Enter the terminal, execute the following command

cd ~/cocos2d-x-2.1.4/tools/project-creator/
python create_project.py -project game01 -package com.ookcode.game -language cpp

create_project.py require three parameters (project name: I have here is game01, the package name: I have here is com.ookcode.game, language: cpp | js | lua)

Successful execution shows the following information

proj.ios        : Done!
proj.android        : Done!
proj.win32        : Done!
proj.mac        : Done!
proj.blackberry        : Done!
proj.linux        : Done!
proj.marmalade        : Done!
New project has been created in this path: /Users/ookcode/cocos2d-x-2.1.4/projects/game01
Have Fun!

Game01 into the directory, you can see these items

Classes    
Resources        
proj.android    
proj.ios    
proj.mac    
proj.win32
proj.blackberry    
proj.linux    
proj.marmalade

How, setting up the whole platform gave you, and share a Classes folder, that you update the code on one platform, all platforms have been updated.

 

Fourth, the project editor ios

Enter game01 / proj.ios / directory, simply double-click to open the game01.xcodeproj (Do not say you did not install xcode)

Then run it can run up

Here I have made a mistake is 2, that is, has been run in this directory cocos2dx, life and death do not run up

Here To select game01, otherwise it becomes been a build cocos2dx

This HelloWorldScene.cpp is your code, you can modify yourself, but because all platforms are used in this, so remember to also run on other platforms under changed after

 255 If an error occurs, exit restart XCODE

V. Andrews editing project (focusing on the more complex)

1. Download the ADT Bundle

http://developer.android.com/sdk/index.html

(To extract the main directory, rename adt-bundle, in order to facilitate the following write path)

2. Download NDK (the latest version is: android-ndk-re8)

http://developer.android.com/tools/sdk/ndk/index.html

(Extract to your home directory)

3. E Clipse CDT plug-in installation

1) install Chinese language pack http://www.eclipse.org/babel/downloads.php

The menu bar: Help ------> Install New Software ------> enter the following address Enter at Work with the frame.

http://download.eclipse.org/technology/babel/update-site/R0.11.0/kepler

Select Simplified Chinese: Babel Language Packs in Chinese (Simplified)

An Tuti then is to choose Simplified Chinese show a step by step installation

2) Installation C / C ++ Development Tools

(1) 2 at the same input http://download.eclipse.org/releases/galileo Work with the frame

Select Collaboration-> Mylyn Bridge: C / C ++ Development, installation, restart eclipse

(2) After selecting the input URL supra Programming Languages-> Eclipse C / C ++ Development

3) Create a HelloWorld project of c ++

 

When you run may have the following error:

gcc: command not found

g++: command not found

打开xcode->preferences->Downloads

You need to download and install the Command Line Tools, the installation is complete, restart Eclipse, then re-run the c ++ project, you will see long-lost HelloWorld in Console!

4. Global Variables Configuration

进入终端,执行以下命令

vim ~/.bash_profile

按i进行编辑,输入以下路径

export COCOS2DX_ROOT=/Users/ookcode/cocos2d-x-2.14/
export NDK_ROOT=/Users/ookcode/android-ndk-r8e
export ANDROID_NDK_ROOT=/Users/ookcode/android-ndk-r8e
export ANDROID_SDK_ROOT=/Users/ookcode/adt-bundle/sdk
export PATH=$ANDROID_NDK_ROOT:$PATH
export PATH=$ANDROID_SDK_ROOT:$PATH

按ESC,再输入:wq 保存并退出(基本的vi命令要会)

******这里是我的路径,切记得换成你自己的*******

5.用NDK编译android项目

进入终端,执行以下命令

cd ~/cocos2d-x-2.1.4/projects/game01/proj.android
./build_native.sh

然后就是漫长的编译

Compile++ thumb  : cocos2dcpp_shared <= main.cpp
Compile++ thumb  : cocos2dcpp_shared <= AppDelegate.cpp
Compile++ thumb  : cocos2dcpp_shared <= HelloWorldScene.cpp
Compile++ thumb  : cocos_extension_static <= AssetsManager.cpp
Compile++ thumb  : cocos_extension_static <= CCBFileLoader.cpp
………
………

当看到

Install        : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.so
make: Leaving directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'

就编译成功了

6.导入android项目

在eclipse中右键,new->project

 

选择Android Project from Existing Code

Browse到game01的proj.android目录

导入进来后我们发现有这样的错误

这是由于cocos2dx的文件没用正确的包含进来

右键项目->properties->Java Build Path

在Source里点Link Source

Browse到/cocos2d-x-2.1.4/cocos2dx/platform/android/java/src

然后随便取个名字,确定,刚才的错误就消除了!

--------------------------------------------------------------------------------------------------

2013年7月31日更新:

可以直接把/cocos2d-x-2.1.4/cocos2dx/platform/android/java当做一个安卓工程导入,然后都不用设置Link Source,一劳永逸!

--------------------------------------------------------------------------------------------------

7.创建AVD模拟器

注:cocos2d-x需要4.0.3以上的模拟器才能运行,真机无所谓

创建AVD是记得勾选Use Host GPU

右键项目->Run As -> Run Configurations-> Target

在最底部输入

8.运行项目

右键项目-> Run As -> Android Application

然后选择刚才创建的AVD,然后你可以去先喝杯茶(模拟器启动那叫一个慢~

9.编辑项目

千万别在eclipse里面写c++的代码, CDT真受不了。

As mentioned above, the whole project is to share a platform of classes, so that we can open the project with xcode ios

HelloWorldScene.cpp open this file, we make some simple changes

Find this line of code, we give him a modified font

CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "Arial", 24);

Change

CCLabelTTF* pLabel = CCLabelTTF::create("Hello World", "fonts/Marker Felt.ttf", 128);

You may be wondering why the font to write "fonts / Marker Felt.ttf"

If you want to support it ios Marker Felt write directly on the line, but Andrew did not do this, we can see that there is fonts directory under the project directory Andrews, so you have to be supported by such an approach Andrews

(But I doubt that, ios obviously useless fonts to this directory, it is judged is how this font)

10. Run the modified project

Click Run in the xcode

Found it, change the font!

Then follows a android project, because the code is modified, it must be recompiled

Re-entering the terminal, enter the following code

cd ~/cocos2d-x-2.1.4/projects/game01/proj.android
./build_native.sh

The last time the compiler would not want to spend so as long as no further compile code once cocos2dx

Using prebuilt externals
make: Entering directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'
Compile++ thumb  : cocos2dcpp_shared <= HelloWorldScene.cpp
SharedLibrary  : libcocos2dcpp.so
Install        : libcocos2dcpp.so => libs/armeabi/libcocos2dcpp.so
make: Leaving directory `/Users/ookcode/cocos2d-x-2.1.4/projects/game01/proj.android'

Appears above code says that compilation was successful

We go back to eclipse, right-project -> Run As -> Android Application

 

 

Reproduced in: https: //my.oschina.net/zhepama/blog/265024

Guess you like

Origin blog.csdn.net/weixin_34356555/article/details/91927354