Cocos2d-x android environment construction and win32 program transplanted to android)

Source: Internet
Author: User

Read these two articles before reading this article.

I, Cocos2d-x learning windows 7 android Environment Construction

Http://www.cnblogs.com/lhming/archive/2012/06/27/2566460.html

 

If you have read this article and there is no problem, please ignore it here.

 

I. Here I will first give you suggestions on the version:

 

1, if you are a completely new, it is recommended that you download cocos2d-x 1. the version of x, since version 2.0 and cocos2d will use opengles2.0, which means more powerful graphic functions, less compatibility, and earlier android versions do not support gles2.0. and the vast majority of PC machines using android simulator does not run based on gles2.0 version, which means that you use cocos2d-x 2. the android program compiled by x cannot be debugged on the PC in real time, but can only be recorded to a newer android instance for real-time debugging and development,

 

Of course, if a game developed using cocos2d 1.x runs on a low-end machine, it cannot express the effect of the cocos2d-x engine.

 

2, it is recommended that you use jdk version above 1.6, preferably 1.7, because jdk version below 1.6 does not support some language features, such as @ overload, this will make cocos2d-x-based java the link file will report an error. Although you can directly remove the @ overload keyword, it is always troublesome,

 

3. About the android ndk version selection and official website, since ndk versions earlier than r4 and r4 do not support stl, and cocos2d is exactly required, you must use r5 or above. version. The latest version in this article is r8,

 

2. Suggestions for configuring environment variables:

1. The environment variable configuration of NDK is used to call the compiler when c ++ is compiled into an android program. It is extremely important. Once an error occurs or fails to take effect, compilation fails. the configuration process is carried out on cygwin, because android c ++ compilation must be carried out in the linux environment, cygwin is a winter simulation of the linux environment, and the article says it should be in the user directory. add the bash_profile File

NDK_ROOT=/cygdrive/e/android-ndk-r8-windows/android-ndk-r8export NDK_ROOT

This means that, once you enter the system, the ndk path is sent to the linux environment variable ,. the bash_profile file is responsible for executing the commands in the file once when the linux system is started. Here, the ndk path is imported to the linux environment variable every time the linux system is started. After adding the file, log on again. cygwin environment, run cd $ NDK_ROOT once, if the ndk directory can be successfully entered, it is already added, if no response, you can try in. adding the same content to the bashrc file and logging on to cygwin again usually succeeds,

 

Here we will talk about cygwin's directory structure. cygwin's root directory is cygwin's installation directory. If you want to jump to another drive letter, you only need to enter the/cygdrive/directory to see your the drive letter of the computer. For example, if you want to enter the drive e, it is the/cygdrive/e/directory.

 

 

After the event, you can read the second article.

II. Creating Android projects and compiling with Cocos2d-x Learning

Http://www.cnblogs.com/lhming/archive/2012/06/27/2566467.html

 

It is still the above suggestion. If you have no problem, you should be soy sauce or soy sauce.

 

1, this create-android-project.bat must be configured directory, cygwin, android sdk and android ndk, must be correct !!!

 

2. If the java link file and jdk version earlier than 1.6 are generated, an error will be reported.

 

Idea, etc. The purpose of importing eclipse is to use eclipse to package the program for apk. The packaging work is done by eclipse, so do not do it yourself.

 

4. If you have generated a java link file, remember to add the corresponding so library file to the main java file. For example, if your project file name is testcocos2d, there must be one testcocos2d. the java file is in the src folder under the android directory, and there will certainly be code similar to this at the end of the java file.

static {         System.loadLibrary("game");}

The meaning here is to import the game library file, so what library files do you want to import here? In general, it is all the library files, libraries, and exact descriptions required by your program. in the android directory

All so files in the folder android \ libs \ armeabi, such as the project contains a libgame. so file, then remove the previous lib and suffix. so, you can import the "game" library in the java file. If you still see libcosdenshion. so and other libraries must be added to the main java file. Otherwise, the apk file can be generated successfully, but an error will be reported during the runtime !! The reason is obvious, the library file is not specified during running, and an error is reported.

 

 

Here is an article to teach you how to convert a program compiled in windows into an android program.

III. cocos2d-x Study Notes 06: How to port win32 to android

Http://4137613.blog.51cto.com/4127613/758783

 

There is an attachment at the bottom. If you think it is too troublesome, you can post it here.

 

Take adding Box2D to HelloWorld as an example to record the pitfalls that need attention. BallCC is the Android project corresponding to HelloWorld, and the red font is the place to be changed, hoping to help others. Step 1: add $ (SolutionDir) to Additional Include Directories. Step 2: Add libbox2d. lib to Additional Dependencies to ensure that libbox2d. lib can be run in VS and has nothing to do with Android. Step 3: F: \ Dev \ cocos2d-1.0.1-x-0.10.0-Clent \ BallCC \ Classes under Android. mk to LOCAL_PATH: = $ (call my-dir) include $ (CLEAR_VARS) LOCAL_MODULE: = game_logicLOCAL_SRC_FILES: = AppDelegate. cpp \ HelloWorldScene. cpp \ sdBall. cpp \ sdDangBan. cpp \ ODSocket. cpp LOCAL_C_INCLUDES: = $ (LOCAL_PATH)/http://www.cnblogs.com/cocos2dx \ $ (LOCAL_PATH)/http://www.cnblogs.com/cocos2dx/platform \ $ (LOCAL_PATH)/http://www.cnblog S.com/cocos2dx/include \ $ (LOCAL_PATH)/http://www.cnblogs.com/CocosDenshion/include \ $ (LOCAL_PATH)/http://www.cnblogs.com/cocos2dx/lua_support \ $ (LOCAL_PATH )/.. /.. LOCAL_LDLIBS: =-L $ (call host-path, $ (LOCAL_PATH )/.. /android/libs/$ (TARGET_ARCH_ABI) \-lcocos2d-lcocosdenshion-lbox2d \-L $ (call host-path, $ (LOCAL_PATH)/destroy (TAR GET_ARCH_ABI)-lcurl include $ (BUILD_SHARED_LIBRARY) Step 4: android under F: \ Dev \ cocos2d-1.0.1-x-0.10.0-Clent \ BallCC \ Android \ jni. mk to LOCAL_PATH: = $ (call my-dir) include $ (CLEAR_VARS) subdirs: = $ (addprefix $ (LOCAL_PATH)/http://www.cnblogs.com/./,$ (addsuffix/Android. mk, \ Box2D \ cocos2dx \ CocosDenshion/android \) subdirs + = $ (LOCAL_PATH)/http://www.cnblogs.com/Classes/Android.mk $ (LOCAL_PATH)/hellowor Ld/Android. mkinclude $ (subdirs) Step 5: F: \ Dev \ cocos2d-1.0.1-x-0.10.0-Clent \ BallCC \ android \ jni Application. mk change to # it is needed for ndk-r5APP_STL: = stlport_staticAPP_MODULES: = cocos2d cococosdenshion box2d game_logic game step 6 F: \ Dev \ cocos2d-1.0.1-x-0.10.0-Clent \ BallCC \ android \ src \ com \ android \ BallCC under the BallCC. add static {System. loadLibrary ("cocos2d"); System. loadLibrary ("cocosdenshion"); System. loadLib Rary ("box2d"); System. loadLibrary ("game_logic"); System. loadLibrary ("game") ;}... It took a day to complete the last step. Why are there so many pitfalls. If the last step is left blank, compilation is fine, but running on the mobile phone will crash.

 

 

Finally, if you encounter an error, please look at the sample file, each cocos2d-x packet, will come from the example tests and helloworld, one is to demonstrate all the features of one is to introduce the program framework, if you don't understand it, take a look at it. It is very important. For example, you won't compile the android package or encounter an error. You can also take a look at the test in the tests directory. how to write the android directory configuration file. how was mk written, right, android. there are three mk files, one at the top level of the Classes directory, one in the android directory of jni, and one in the subdirectory of the directory. If the compilation fails, Please carefully compare android. mk files ,,

 

 

And the example program for the search for cocos2d-x api usage is also quite helpful! Cocos2d-x was the version updated quickly, some api usage has been completely different, the sample code on the Internet will be outdated, but the approximate concept is the same, so now you can view you my own cocos2d-x version of the sample file, where will introduce the use of the latest api, code compilation error? See the sample code ~ ^ ___ ^

 

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.