Cocos2dx-android First Experience

Source: Internet
Author: User

Windows under Android platform Cocos2dx.


First you have to have the following eclipse (ADT, CDT), Cygwin, android-ndk, android-sdk, download the installation yourself, do not explain in detail.


First, download COCOS2DX.

Http://www.cocos2d-x.org/download

My cocos2dx directory is D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4

Second, the first Android version configuration, need to modify several places.

1, enter the directory, modify create-android-project.sh, modify the NDK,SDK directory for your own

# Set Environment paramters
ndk_root_local= "/cygdrive/d/tool/android-ndk-r8b"
Android_sdk_root_local= "/CYGDRIVE/D/TOOL/ANDROID-SDK"

2. Then, modify the Create-android-project.bat file and modify it to your own directory.

:: Modify it to work under your environment
Set _cygbin=d:\progra~1\cygwin\bin
If not exist "%_cygbin%" echo couldn ' t find Cygwin at "%_cygbin%" & Pause & Exit 4


:: Modify it to work under your environment
Set _androidtools=d:\tool\android-sdk\tools
If not exist "%_androidtools%" echo couldn ' t find Android SDK tools at "%_androidtools%" & Pause & Exit 5


:: Modify it to work under your environment
Set _ndkroot=d:\tool\android-ndk-r8b
If not exist "%_ndkroot%" echo couldn ' t find ndk at "%_ndkroot%" & Pause & Exit 6

Note: If the file path has a space, run cmd, enter the directory, enter the debug return, then-R run, then-quit, then you can see the short path fixed with the space.

Similar to the set _cygbin=d:\progra~1\cygwin\bin above

Third, build Android project

Run the Create-android-project.bat and follow the prompts to step through the steps. When the operation is completed, a project folder is generated, in the directory, my Samplehelloworld

D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\SampleHelloWorld

Iv. Compiling dynamic libraries

Go to directory D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\SampleHelloWorld\proj.android and find build_native.sh

Add Export ndk_root=/cygdrive/d/tool/android-ndk-r8b (the corresponding directory for yourself here)


Run build_native.sh, wait a minute and compile.

......

SharedLibrary:libgame.so
Install:libgame.so = libs/armeabi/libgame.so

V. Operating Procedures

1, first import LIBCOCOS2DX, located in the D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\cocos2dx\platform\android\java directory.

2, then import the project just generated, add the first step of the Lib library, you can run.



As above, run no problem, if you make a change, then compile and run it? Here's a description

Compiling Java code Naturally Needless to say, changed to save the can, but compiled COCOS2DX C code, how to configure?


Vi. first conversion to C project

With the item selected, right-new,c/c++ below is a convert to a C + + project (ADD/C + + Nature), click Next, Tick Samplehelloworld,

Select Cygwin gcc,finish to the right of makefile project below.

Vii. Modify ANDROID.MK and application.mk (note that the add path is your own directory)

1, add the following two lines in the ANDROID.MK

$ (call Import-add-path, D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4) \
$ (Call Import-add-path, D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\cocos2dx\platform\third_party\android\ prebuilt) \

$ (call import-module,cocosdenshion/android) \
$ (call import-module,cocos2dx) \
$ (call import-module,extensions)

2, add the following application.mk

App_stl: = gnustl_static
App_cppflags: =-frtti-dcocos2d_debug=1
App_cflags + =-wno-error=format-security
Ndk_module_path:=d:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\cocos2dx\platform\third_party\android\ prebuilt

Eight, the series Configuration and modification (note replacement for their own directory)

Enter the Project Properties dialog box Project->properties

1, find Builder, in the dialog box appears to remove the CDT bulider tick,

then click New and select Program,ok to enter.

Take a name samplehelloworldbuilder yourself,

and then location for D:\TOOL\android-ndk-r8b\ndk-build.cmd,

working diretory for ${workspace_loc:/samplehelloworld}, then apply, OK.

2. Then Build in C + +

1) Click, the dialog box appears, remove the use of the default build command tick,

in the following build command fill out bash ${workspace_loc:/samplehelloworld}/build_native.sh

2) then find the environment inside, click Add,

name is Ndk_module_path,

value is D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\cocos2dx\platform\third_party\andro Id\prebuilt,

make the following tick add to all configurations OK again.

3. Then find paths and Symbols

1) in includes, click Add on the right,

Fill in the diretory in the Pop-up dialog box D:\TOOL\android-ndk-r8b\platforms\android-9\arch-arm\usr\include

Tick add to all configurations and add to all languages OK

Repeat this step and add the following path one at a

D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\cocos2dx\include

D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\CocosDenshion\include

D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\CocosDenshion\android

2) Source location, click on the link Folder on the right,

floder name fill in the classes, tick link to folder in the file system

Select D:\2013\cocos2dx\cocos2d-x-2.1.4\cocos2d-x-2.1.4\SampleHelloWorld\Classes and OK

Repeat this step, floder name is COCOS2DX, path is D:\2013\COCOS2DX\COCOS2D-X-2.1.4\COCOS2D-X-2.1.4\COCOS2DX


Apply again OK.

Nine, run

Run just like a normal Android program.

X. SUMMARY of issues

If the Make:* *no rule to made target error occurs at compile time, delete the obj directory below the project.

If the prompt permission is insufficient, then add the permission, chmod-r 777 "file directory".


If you do not understand the place, you can comment on comments. Progress together.

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.