Pack Cocos2d-x games into an Android app

Source: Internet
Author: User

1. Open Eclipse (The CDT,ADT, and NDK are already installed) and import the Cocos2d-x Android project.

2. After importing Java source code will appear compile error, open the root folder of Cocos2d-x engine \cocos2dx\platform\android\java\src, copy the org file under SRC to the Project src folder, java file compiled by



3. Configure environment variables and resource paths. Right click on the project name, press the Alt+enter key, enter the linked resources in resource, click New, the following dialog box appears



Name Input Cocos2dx,location Enter the root folder of the Cocos2d-x engine, click OK and then tap new again.

Name Input Project_loc,location Enter the root folder of the Cocos2d-x engine \projects\ your project \proj.android, then click OK to configure the resource path bindings



With C + + build selected, see Build command: Change the contents of this text box to the installation folder of the ndk of your native \ndk-build.cmd (the folder cannot have spaces)



Next, select the Environment,add three variables under C + + Build


The name and value of the three variables are each

COCOS2DX The root folder of the Cocos2d-x engine

Ndk_module_path The root folder of the Cocos2d-x engine; cocos2d-x Engine root Folder \cocos2dx\platform\third_party\android\prebuilt

Ndk_root NDK's installation folder



4. Copy the resource files under the resources to the root folder of the Cocos2d-x engine \projects\ your project \proj.android\assets

5. Writing the Jni\android.mk file



Increase the CPP file name of your project in Local_src_files



If the project file is a lot of words bound to write trouble, and need to change the very easy to write errors, in the next article, with the Py script to avoid this situation

If you have introduced the third party libraries after writing the local_src_files, you need to change the following two places (for example, Iconv library)

Download the Iconv library and copy it to the Cocos2d-x root folder


Add the following two more places



Why do you write this in this way, you can find it from the Iconv root folder \android.mk



This allows the project to be

#if (Cc_target_platform = = Cc_platform_win32) #include ". /iconv/iconv.h "#pragma comment (lib," Libiconv.lib ") #elif (Cc_target_platform = = cc_platform_android) #include". /.. /.. /libiconv/include/iconv.h "#endif

When using Iconv on the Android platform also to turn the const char** strong to char** (Android real egg pain), where the pin is a const char** type,

#if (Cc_target_platform = = Cc_platform_win32) if ( -1 = = Iconv (iconvh,pin,&strlength,&outbuf,&outlength)) { #elif (Cc_target_platform = = cc_platform_android) if ( -1 = = Iconv (ICONVH, (char * *) pin,&strlength,&outbuf,& Outlength)) {#endif


6. Compile the project, assuming you see the console output



Indicates that the compilation was successful.


Pack Cocos2d-x games into an Android app

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.