Mac system perfectly configures Cocos2d-x 2.2.3 's Android+ios dual platform environment

Source: Internet
Author: User

Transferred from: http://www.cnblogs.com/wt616/p/3758828.html


Readme: Self-Test cocos2d-x2.2.5 version is OK. In accordance with the following documentation to configure the control, or a good new project, do not copy other local projects, or there may be a variety of inexplicable bugs.


Note: The cocos2d-x version of this article is 2.2.3, the later version may be slightly different, the lower version is not recommended for reference

First you need to configure the Xcode environment

Download Cocos2d-x

Then download the entire source of Cocos2d-x:http://www.cocos2d-x.org/download Select the version of 2.2.3

Unzip after download, suggest moving to document

2.2.3 version starts, Cocos2d-x will not be created through the Xcode built-in template, but must be created through scripting

Here, my source path is:/users/mac/documents/projects/cocos2d-x-2.2.3/, the following all the same path can be based on your own location to place cocos2d-x source code to replace.

Now use its own script to create a new project

New Project

First Terminal entry: Cd/users/mac/documents/projects/cocos2d-x-2.2.3/tools/project-creator

Then execute the script:./create_project.py-project mygame-package Com.wangtao.mygame-language CPP

Mygame here is the project name, please change according to your own needs

The com.wangtao.mygame here is the package name, please change according to your own needs. The changed package name takes effect at the same time in both Xcode and eclipse environments.

After the script execution is complete, the new project is under this path:/users/mac/documents/projects/cocos2d-x-2.2.3/projects

Find this item and go to find Proj.ios folder after finding Mygame.xcodeproj open to enter Xcode development game.

Android Environment configuration

Eclipse for Mac:http://eclipse.org/downloads/
Android SDK for Mac:http://developer.android.com/sdk/index.html

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

Adt:http://dl.google.com/android/adt/22.6.2/adt-bundle-mac-x86_64-20140321.zip

Note Download the Mac version and match if your system is 32-bit or 64-bit. Several packages are relatively large, download speed is slow, we recommend the use of support for the continuation of the tool download.

Configuring Environment variables

In order for the compiler to quickly navigate to its path based on the name abbreviation, it is necessary to configure and save their mapping relationship.

Open terminal, and then enter Pico. Bash_profile Enter
Then manually enter the following path in:

Export android_sdk_root=/users/mac/documents/projects/sdk/

Export android_ndk_root=/users/mac/documents/projects/android-ndk-r9d/

Export COCOS2DX_ROOT=/USERS/MAC/DOCUMENTS/PROJECTS/COCOS2D-X-2.2.3/

Export ndk_root=/users/mac/documents/projects/android-ndk-r9d/

Export path= $PATH: $ANDROID _sdk_root

Export path= $PATH: $ANDROID _ndk_root

Note that the above input process, "=/" can not have spaces around, otherwise it will fail to configure

After the input is complete, Control+x saves, then prompts to save, enter Y, and finally return!
After the configuration path is complete, it is recommended to monitor for correct configuration
Verify the path step: Close your "terminal", reopen, if the previous path configuration has a problem, then re-open "terminal" will appear the following prompt:-bash:exoort:command not found If there is no such hint, the path configuration is complete.

Build Android Project

Go to the Eclipse folder, launch Eclipse, create a new project, select Android Project from Existing Code, click Browse, select/users/mac/documents/projects/ Cocos2d-x-2.2.3/projects the game item you want to import, go to the corresponding game folder, select the Proj.android folder, then click Open.

After the project is imported, you can see that the resources under the assets file are the corresponding resources in Xcode, and you will not need to copy the resources back and forth, greatly saving the time of the project porting to the Android platform.

In addition, the project automatically generates entry activity, which inherits from Cocos2dxactivity. However, if the project is imported for the first time, this library is not and needs to be imported. To do this, create a new project, select Android Project from Existing Code, click Browse, select/USERS/MAC/DOCUMENTS/PROJECTS/COCOS2D-X-2.2.3/ Cocos2dx/platform/android folder.

Before the final compilation, special attention should be paid to:

1. Check the code in the Jni/hello/cpp/main.cpp of this project in Eclipse, by default, the above Inlude a "hellowolrdscene", if your game deleted this class, then here also to remove this include

2, check build_native.sh, in the # options need to add Ndk_root:ndk_root= "/users/mac/documents/projects/android-ndk-r9d"

Final compile and run

Enter the terminal, and execute this compilation script directly according to the build_native.sh location in the project, such as:

/users/mac/documents/projects/cocos2d-x-2.2.3/projects/mygame/proj.android/build_native.sh

The purpose of this compilation is to generate a. so file and pack it into an Android apk, and if the compilation succeeds you will see the following text

[Armeabi] SharedLibrary:libcocos2dcpp.so

[Armeabi] Install:libcocos2dcpp.so = libs/armeabi/libcocos2dcpp.so

If the compilation error, will show the corresponding cause of the error, it is strongly recommended to ensure that in Xcode compiled through the premise, then the Android. So compiled.

After compiling the pass, click on the project root node and press the F5 key to see more libs/armeabi/libcocos2dcpp.so in the project.

Finally, with Eclipse's run function, you can generate the APK directly.

Permission to give

The "Permission Denied" solution appears in the terminal Access file under Mac:

A file has 3 kinds of permissions, read, write, executable, you do not have the ability to execute the file, you need to add executable permissions.

1. Under the terminal, CD to the file directory

2. Execute command chmod a+x./File name

NDK not compatible

During compilation, you may encounter such an error message: Format not a string literal and no format arguments [-werror=format-security]

Reason:

ANDROID-NDK-R9 and Eclipse version incompatibility issues

One of the scenarios (I found):

Add a word to the proj.android/jni/application.mk of the corresponding project

App_cflags + =-wno-error=format-security

Refreshing dual platform development at the same time

It is recommended to play the game development and debugging in Xcode. Every time you need to build an Android apk, execute the build_native.sh script through the terminal and then click F5 to refresh the project root directory of Eclipse. So after the file is compiled and packaged one go.

The only trouble is that the iphone and Android phones may need to be plugged back and forth, but this is the highest cross-platform development efficiency for game developers.

This article by Wang Yu Original, reproduced please specify the original address.


Mac system perfectly configures Cocos2d-x 2.2.3 's Android+ios dual platform environment

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.