Cocos2d-x cross-compiled to Android

Source: Internet
Author: User

Ccocos2d-x is an open source framework based on the MIT protocol, used to build games, applications and other graphic interface interactive applications. Its biggest feature is its cross-screen performance. It supports many platforms such as IOS, Android, Windows, and WindowsPhone, saving a lot of manpower and material resources in creating multi-platform games. Next, introduce the cocos2d-x project cross-compilation to Android platform, generate APK Installation File process.
I. Cross-compiled cocos2d-x to Android needs Java, Python environment, need to be set up first, here will not go into detail.
2. Build an Android development environment under Eclipse (eclipse and Android SDK are required)The Android official website provides an integrated development environment. After downloading the environment, unzip the package and start eclipse, which is very convenient. : Http://developer.android.com/sdk/index.html#downloadselect the corresponding folder with your computer, download the package and decompress it to the eclipse folder, and then try to start ecplise. If it can be started, the Android development environment can be set up.
3. Install Android NDKAndroid NDK is a parsing and compilation tool for C/C ++ during android cross-compilation. : Bytes
4. Install cygwinDownload cygwin: http://www.cygwin.com/download cygwin from the official website of cygwin. Use http //: mirrors.163.com to download the source. Most importantly, when selecting the package to be downloaded, check the Devel item as Install. The make tool is available in the Devel package. It is required to compile Android. Other packages are unnecessary. Do not select this option. It seems that all packages are 7 or 8 GB. You can go down to dawn.
Next, configure the cygwin NDK environment (cygwin uses NDK to compile C ++ Code) to open the home folder of the cygwin installation directory, which contains an automatically generated username folder (for example, my example is: c: \ cygwin \ home \ chen. bash_profile file, add the NDK path at the end of the file (the path is consistent with the NDK environment variable): pay special attention to the path format of cygwin, if '/' is used instead of '\' of windows, cygdrive refers to a local disk and g refers to a g disk.
5. Use cygwin to compile the cocos2d-x ProjectOpen proj. android folder in the cocos2d-x project 1) Open the jni folder in the proj. android folder, edit the Android. mk file in it, and manually add all cpp names in the project in LOCAL_SRC_FILES. You can also use the following code to automatically traverse the Classes folder and add the cpp class (also in Android. mk, replace the code in LOCAL_SRC_FILES with the following code)

# Define walk, a function that traverses directories and subdirectories $ (wildcard $ (1) $ (foreach e, $ (wildcard $ (1)/*), $ (call walk, $ (e) endef # traverse the Classes directory ALLFILES =$ (call walk, $ (LOCAL_PATH )/.. /.. /Classes) FILE_LIST: = hellocpp/main. cpp # extract all from all files. cpp file FILE_LIST + = $ (filter %. cpp, $ (ALLFILES) LOCAL_SRC_FILES :=$ (FILE_LIST: $ (LOCAL_PATH)/% = %) </span>
2) Run cygwin and return to proj. android. Drag the build_native.sh file in the directory to the cygwin window to compile the project. Compiled successfully:
6. Import the project in eclipse and generate the Apk File1. import the project first: Right-click and select import, and then your cocos2d Project (note that your cocos2d project is not the proj. android folder)
2. Because eclipse needs to call cygwin's bash program to compile the android project, it is necessary to configure cygwin information in eclipse. First, right-click the project and choose property> builders> New> Program to create a New compilation Program. The following is my program information:

NameYou do not need to change the value to Native_Builder. LocationModify the bashprogram to the location of bash.exe. Working DirectoryChange to the bin directory of your cygwin ArgumentsChange the last APP = SameGame to your project name (SameGame is my project name)
Click OK and use UP to adjust Native_Builder to the top.

Then select C/C ++ Build-> Enviroment-> Add to Add your cygwin bin path and click OK.


Then, you can right-click the running program (run as android application), and then run the proj. the APK file of this project will be generated in the bin folder under adnroid, And you can install it on your mobile phone !!

Note that the android virtual machine does not support OpenGL, so the cocos2d project cannot be tested on the Virtual Machine. Therefore, the generated APK file must be run on the real machine.
FAQs:1. in ecplise, click run as android application... zip add failed is actually a file access permission issue. When you use cygwin to compile code, you do not declare more advanced access permissions, so some resources cannot be accessed.
[2014-06-03 20:02:52 - MyApp]       Unable to add 'G:\cocos2d-x-2.2.3\projects\MyApp\proj.android\assets\crystal_guardian\background.jpg': Zip add failed[2014-06-03 20:02:52 - MyApp] ERROR: unable to process assets while packaging 'G:\cocos2d-x-2.2.3\projects\MyApp\proj.android\bin\resources.ap_'
Solution: When cygwin is used, declare proj. android as chmod-R 755 * access mode. After entering the cocos2d project, enter chmod-R 755 * proj. android to declare the permission to access proj. android.
2. How can I change the landscape and Landscape Display? By default, the image is displayed on a horizontal screen in eclipse. to display the image on a vertical screen, first open AndroidMainifest in the project file. xml file. You can see android: screenOrientation = "landscape" in the activity and change it to android: screenOrientation = "portrait" // portrait.
The above is the whole process of cross-compiling cocos2d-x to Android, hope to help you. This article reference article: http://blog.csdn.net/sttyytw/article/details/17005263, some pictures from the above blog.

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.