Windows Platform Cocos2d-x 3.0 Android development environment

Source: Internet
Author: User

Cocos2d-x upgrade to 3.0 after the change is not small, in addition to the changes in the API (mainly the function and class name changes, as well as the use of c++11 a lot of features, Function/bind, Lamda, Std::thread ... ), creating and compiling the project also made some simplification adjustments. This paper mainly discusses the environment setting and the project creation and compiling process of cocos2d-x3.0 in the development of Android platform.

1. Initial setup

In addition to the PYTHON,JDK required by 2.x, the Android SDK and the NDK need to be deployed apache-ant.

1) Set the Java environment variable in path:

java_home=c:\jdk_xx.xx.xx

Path plus%java_home%\bin;

Classpath=.; %java_home%\lib;%java_home%\lib\tools.jar

2) Install Python version 2.x.

3) After deploying the Android SDK, NDK, ant, Run ... \cocos2d-x-3.0\ setup.py. Prompt for ndk,sdk and ant directories, note here that ANDROIDSDK is set to ... the \ADT-BUNDLE-WINDOWS-X86\SDK,NDK directory is set to ... \android-ndk, and the Ant directory is set to ... \ Apache-ant\bin, and the first two are set to the root directory is different, to set to the bin directory, otherwise does not take effect, the deployment of the APK will be prompted to find Ant.

4) Automatically close the setup.py script when the three directory settings are complete. The development environment Setup is complete.

2. Create a project

2.x

Cocos2d-x\tools\project-creator directory, command line execution Python create_project.py–project abc–package com.xyz.abc–language CPP Create project

Create a good project directory in Cocos2d-x\projects, cannot replicate to other paths, otherwise there will be engineering dependency issues.

3.0

CMD command line into the project path of your choice, execute Cocos new Mygame-p com.your_company.mygame-l CPP

Wait for the project to be created.

Version 3.0 copies the dependent COCOS2DX source files to the project directory that you created, under the Cocos2d folder. So there is no dependency problem caused by copy engineering.

3. Compiling the project

After creation, the CD enters the engineering directory, executes the Cocos compile–p android–j 4 compilation project, Cocos run–p android–j 4 compile + deploy apk+ run.

-P parameter Specify platform

The-j parameter specifies how many threads are used to perform the compilation, and the official argument is that the compilation speed can be speeded up. (option available)

The default is debug compilation, and-m release can be specified to compile as a release version. Note that release must be lowercase and written as release is invalid.

See the official documentation for more parameters:

Https://github.com/cocos2d/cocos2d-console/issues/27

4. Deploy APK

Cocos deploy–p Android Deployment compiled good Apk,cocos run–p Android can be compiled for direct deployment.

5. Cleaning works

The official documentation of the Cocos Clean command prompts error:argument ' clean ' not found after execution.

Take a look at the cocos2dx command script, directory in Cocos2d-x-3.0\tools\cocos2d-console.

To view the Cocos2d.ini in the bin directory:

#

#cocos2d Command line tool configuration file

#

[Plugins]

Project_new. Ccpluginnew

Project_compile. Ccplugincompile

Project_run. Ccpluginrun

Project_deploy. Ccplugindeploy

Plugin_jscompile. Ccpluginjscompile

#plugin_version. Ccpluginversion

#plugin_install. Ccplugininstall

#plugin_update. Ccpluginupdate

#plugin_clean. Ccpluginclean

#plugin_dist. Ccplugindist

# to Adda new plugin add it's classname here

You can see the Clean command is commented out, only New,compile, run, deploy available, the reason is unclear, then do not have the command cleanup project, instead of manually clean it, very simple, need to clean up when the porj.android directory bin, obj, Libs, Assets, the Gen catalogue is all removed. Can write a script to complete.

6. Development environment

Projects created by the cocos2d-x2.x version can be compiled directly using VS2010. After developing and debugging on Windows, porting to the Android platform is OK. After upgrading to version 3.0, the minimum supported version is vs2012 due to the use of c++11. VS2012 requires more than Win7 OS, unable to debug the program on the XP system.

That being the case, no Win32 project was developed, and the Android platform was compiled directly, eliminating the process of porting.

Command-line compilation deployment Android project has been introduced, the following is to choose an IDE for easy development, here is recommended codeblocks. Create the project steps as follows:

1) Create a codeblocks empty project in the game Engineering root directory.

2) Add all files of classes and cocos2d directories.

3) Precompiled macro definition add Android-specific platform.

Setup is complete and you are ready to develop. The command line needs to be executed at compile time Cocos compile–p android–j 4.

Locate the bug by locating the corresponding line of the source file in Codeblockside based on the error code line prompt for the command line.

Do not add new files only in Codeblocks, but also add Local_src_files in Proj.android/jni/android.mk.

Also, if you need to use the COCOS2DX extensions module, you need to modify the Android.mk file.

Modify the following:

Local_c_includes:= $ (local_path)/. /.. /classes \

$ (Local_path)/.. /.. /cocos2d\extensions

local_whole_static_libraries+= cocos_extension_static

$ (call import-module,extensions)

Add other modules similar to this.

7. Log output

cocos2d-x3.0 Use the new Print function log (2.x version is cclog), we need to use ADB and logcat tools to view the log output (to use ADB on the command line, remember to configure Adt-bundle-windows-x86\sdk\ Platform-tools to Path).

Command line execution adb Logcat, if the Android device is connected to USB or open the emulator, you can see the output log information, but too much information, the program printed important information will soon be flooded, must set the filter conditions.

You can see that the Cocos2d-x log Information format is D/cocos2d-xdebug info (12358): xxxx.

D means debug, which indicates the print priority, the following character, in order from low to High:

V-Detail (lowest priority)

D-Debug

I-Information

W-Warning

E-Error

F-Critical Error

S-no record (highest priority, nothing will be recorded)

For logcat use See http://blog.csdn.net/xyz_lmn/article/details/7004710

The ADB logcat cocos2d-xdebug info:d *:s should be able to filter out the other information, but after the implementation of the discovery of what information is not, which is why?

In addition to create an Android project, debugging found that there is a space in the tag adb can not be properly filtered, the problem is clear, the following need to modify the COCOS2DX log function.

Open Cocos2d\cocos\base\ccconsole.cpp, find the _log function (both log and Cclog call this), inside

#ifCC_TARGET_PLATFORM = = Cc_platform_android

__android_log_print (Android_log_debug, "Cocos2d-x DEBUG Info", "%s", buf);

Modify Cocos2d-x Debug Info to Cocos2d-x_debug_info.

Recompile the project, command line execution Adblogcat cocos2d-x_debug_info:d *:s, can be filtered normally, only show the COCOS2DX log output.

Note that if you modify the Cocos2d\cocos\base\ccconsole.cpp file under the project path, the next time you create a new project, the tag of the log function is Cocos2d-x debuginfo, and you want to You can modify the Cocos2d-x-3.0\cocos\base\ccconsole.cpp. This creates a new project and copies the file to the new project without having to change it every time.


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.