Windows platform cocos2d-x 3.0 android Development Environment

Source: Internet
Author: User

After the cocos2d-x is upgraded to 3.0, the changes are not small, except for API changes (mainly changes in functions and class names, and the use of many features of C ++ 11, function/bind, lamda, std:: thread ...), Some simplified adjustments have also been made to create and compile projects. This article mainly discusses the development of cocos2d-x3.0 In the android platform environment settings and Project Creation compilation process.

1. Initial settings

In addition to python, jdk, android sdk, and ndk required by 2.x, apache-ant must be deployed.

1) set java environment variables in path:

JAVA_HOME = C: \ jdk_xx.xx.xx

Add % JAVA_HOME % \ bin to path;

CLASSPATH =.; % JAVA_HOME % \ lib \ tools. jar

2) install python 2.x.

3) after the android sdk, ndk, ant is deployed, run... \ cocos2d-x-3.0 \ setup. py. Prompt to enter the ndk, sdk, and ant directories. Please note that androidsdk is set... \ Adt-bundle-windows-x86 \ sdk, ndk directory is set... \ Android-ndk, while the ant directory must be set... \ Apache-ant \ bin, Different from the first two, set to the root directory, to the bin directory, otherwise it does not take effect, the system will prompt that the ant cannot be found when the apk is deployed.

4) The setup. py script is automatically disabled after the three directories are configured. The development environment has been set up.

2. Create a project

2. x

Under the cocos2d-x \ tools \ project-creator directory, execute python create_project.py-project ABC-package com. xyz. abc-language cpp to create a project

The created project directory is in cocos2d-x \ projects and cannot be copied to another path, otherwise there will be a project dependency issue.

 

3.0

Run the cmd command line to go to the project path you selected and run cocos new MyGame-p com. your_company.mygame-l cpp.

Wait until the project is created.

Version 3.0 copies the dependent cocos2dx source file to the project directory created by itself, under the cocos2d folder. Therefore, there is no dependency problem caused by the copy project.

3. compile the project

After the creation, cd enters the project directory and runs the cocos compile-p android-j 4 Compilation project. cocos run-p android-j 4 Compilation + deploy apk + run.

-P parameter specifies the Platform

-The j parameter specifies how many threads are used to execute the compilation. The official statement is that the compilation speed can be improved. (Optional)

The default value is debug compilation, and-m release can be used to specify the compilation as the release version. Note: The release must be in lower case. It is invalid to write it as Release.

For more parameters, see the official documentation:

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

4. Deploy apk

Cocos deploy-p: The compiled apk is deployed on android, and cocos run-p android can be compiled and directly deployed.

5. Clean up the project

The cocos clean command in the official documentation prompts Error: argument 'clean' not found after it is executed.

Take a look at the cocos2dx Command Script, directory in cocos2d-x-3.0 \ tools \ cocos2d-console.

View 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

We can see that the clean command has been commented out, and only new, compile, run, and deploy are available. If the reason is unknown, you don't need to clear the project. You can use manual cleanup instead, which is very simple, porj. delete the bin, obj, libs, assets, and gen directories of android. You can write a script.

6. Development Environment

Projects created in the cocos2d-x2.x version can be compiled directly using vs2010. After development and debugging on windows, you can port the SDK to the android platform. After upgrading to version 3.0, the minimum supported version is vs2012 because c ++ 11 is used. Vs2012 requires a Windows 7 OS or later, so you cannot debug the program on the Windows XP system.

In this case, the win32 project will not be developed, and the android platform will be compiled directly, saving the porting process.

The android project has been compiled and deployed through the command line. The following describes how to select an IDE for convenient development. codeblocks is recommended here. To create a project, follow these steps:

1) create a codeblocks Empty Project in the root directory of the game project.

2) add all the files in the Classes and cocos2d directories.

3) pre-compiled macro definitions are added to the specified ANDROID platform.

After the settings are complete, you can perform development. Execute cocos compile-p android-j 4 in the command line when compiling.

Find the corresponding source file line in codeblockside based on the error code line prompted by the command line to locate the bug.

Add LOCAL_SRC_FILES in proj. android/jni/Android. mk instead of in codeblocks.

In addition, if you need to use the cocos2dx extensions Module, you also need to modify the Android. mk file.

Modify as follows:

LOCAL_C_INCLUDES: = $ (LOCAL_PATH)/.../../Classes \

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

LOCAL_WHOLE_STATIC_LIBRARIES + = cocos_extension_static

$ (Call import-module, extensions)

Add other modules.

7. Log output

The cocos2d-x3.0 uses the new print function log (2. version x is CCLog), we need to use adb and logcat tools to view log output (to use adb in the command line, remember to configure adt-bundle-windows-x86 \ sdk \ platform-tools to path ).

Run adb logcat on the command line. If the android device is connected to a USB or a simulator, the output log information is displayed. However, if there is too much information, the printed important information in the program will soon be drowned, filter conditions must be set.

The log information format for the cocos2d-x is D/cocos2d-xdebug info (12358): xxxx.

D Indicates debug, indicating the print priority. The priority is the following characters, and the order is from low to high:

V-details (lowest priority)

D-debugging

I-Info

W-warning

E-Error

F-severe error

S-not recorded (highest priority, nothing will be recorded)

For details about how to use logcat, see http://blog.csdn.net/xyz_lmn/article/details/7004710.

The execution of adb logcat cocos2d-xdebug info: D *: S should be able to filter out other information, but after the execution of the information found nothing, why?

In addition, an android project is created. After debugging, it is found that the tag contains space adb and cannot be correctly filtered. The problem is clear. Modify the log function of cocos2dx below.

Open cocos2d \ cocos \ base \ CCConsole. cpp and find the _ log function (both log and CCLog call this function ).

# 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.

Re-compile the project, command line execution adblogcat cocos2d-x_debug_info: D *: S, can be properly filtered, only display the cocos2dx log output.

NOTE: If cocos2d \ cocos \ base \ CCConsole under the project path is modified. cpp file, next time to create a new project, log function tag or cocos2d-x debuginfo, If You Want To once and for all, you can modify cocos2d-x-3.0 \ cocos \ base \ CCConsole. cpp. When a new project is created, the file is copied to the new project, and you do not need to modify the file every time.

 


Related Article

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.