Cocos2dx developed in windows and compiled to android (1)

Source: Internet
Author: User

Next I will introduce how to use vs2010 to develop cocos2dx and compile it to android. The procedure is as follows:

1. Prerequisites: Your eclipse code can be compiled to an Android mobile phone or virtual machine. If this step is not completed yet, check it with Google Baidu and configure the environment. [My sdk directory is: E: \ android-sdk-windows]

2. Download cygwin and install it. Please take a look at the tutorial online. cygwin must be able to use commands such as gcc, g ++, make, and vi. My installation directory is: E: \ android \ cygwin

3. Download ndk. If ndk does not know what it means, Google Baidu first. Ndk, you just need to download and decompress it in one place. The directory I extracted is: E: \ android \ android-ndk-r7

4. download the latest version of cocos2dx. I decompress cocos2dx in E: \ android \ cocos2d-1.0.1-x-0.13.0-beta. Find in this directory: create-android-project.bat and then edit with cygwin, my create-android-project.bat after modification effect is as follows:

[Plain]
@ Echo off
: This script is used to create an android project.
: You shoshould modify _ ANDROIDTOOLS _ CYGBIN _ NDKROOT to work under your environment.
: Don't change it until you know what you do.
 
Setlocal
 
: Check if it was run under cocos2d-x root
If not exist "% cd %\ create-android-project.bat" echo Error !!! You shoshould run it under cocos2dx root & pause & exit 2
 
If not exist "% ~ Dpn0.sh "echo Script" % ~ Dpn0.sh "not found & pause & exit 3
 
: Modify it to work under your environment
Set _ CYGBIN = E: \ android \ 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 = E: \ android-sdk-windows \ 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 = E: \ android \ android-ndk-r7
If not exist "% _ NDKROOT %" echo Couldn't find ndk at "% _ NDKROOT %" & pause & exit 6
 
: Create android project
Set/P _ PACKAGEPATH = Please enter your package path. For example: org. cocos2dx. example:
Set/P _ PROJECTNAME = Please enter your project name:
If exist "% CD % \ % _ PROJECTNAME %" echo "% _ PROJECTNAME %" exists, please use another name & pause & exit 7
Echo "Now cocos2d-x suppurts Android 2.1-update1, 2.2, 2.3 & 3.0"
Echo "Other versions have not tested ."
Call "% _ ANDROIDTOOLS % \ android. bat" list targets
Set/P _ TARGETID = Please input target id:
Set _ PROJECTDIR = % CD % \ % _ PROJECTNAME %
 
Echo Create android project
Call "% _ ANDROIDTOOLS % \ android. bat "create project-n % _ PROJECTNAME %-t % _ TARGETID %-k % _ PACKAGEPATH %-a % _ PROJECTNAME %-p % _ PROJECTDIR %

: Resolve ___. sh to/cygdrive based * nix path and store in % _ CYGSCRIPT %
For/f "delims =" % A in ('% _ CYGBIN % \ cygpath.exe "% ~ Dpn0.sh "') do set _ CYGSCRIPT = %
 
: Resolve current dir to cygwin path
For/f "delims =" % A in ('% _ CYGBIN % \ cygpath.exe "% cd %"') do set _ CURRENTDIR = %
 
: Resolve ndk dir to cygwin path
For/f "delims =" % A in ('% _ CYGBIN % \ cygpath.exe "% _ NDKROOT %"') do set _ NDKROOT = %

: Throw away temporary env vars and invoke script, passing any args that were passed to us
Endlocal & % _ CYGBIN % \ bash -- login "% _ CYGSCRIPT %" % _ CURRENTDIR % _ PROJECTNAME % _ NDKROOT % _ PACKAGEPATH % "windows"-l-B
 
Pause

There are three modifications: A: set _ ANDROIDTOOLS = E: \ android-sdk-windows \ tools

B: set _ NDKROOT = E: \ android \ android-ndk-r7

C: set _ CYGBIN = E: \ android \ cygwin \ bin

You can change these three places to your own installed directory.

5. Make sure that the eclipse environment configuration is complete. Run your cocos2dx project on vs2010.


6. On cygwin, enter cocos2dx and enter the following command:

Press enter. You will see the following information and enter:

Press enter to display the following information. Enter the following information:

Press enter. Please wait and you will see the following information:

Enter the android version you want to create and add Android2.3.3, then enter 15, for example:

Press enter, cygwin will perform some processing, and then the cocos2dx project is created.
Open the cocos2dx folder and you will see the folder you just created. The folder contains the following folders:

7. In this step, copy the files under the Classes file in the project compiled by vs2010 to the Classes file. Likewise, the files in the Resource under vs2010 are copied to the Resource file.
8. Open the teachYou we just produced and modify the android. mk file under \ Android \ jni. Just add your. cpp file.
9. Open cygwin and drag build_native.sh under \ android to cywin and press enter to compile the file.
 
10. Use eclipse to import the folder android.




From the ComeOnTom Column

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.