Cocos2d-x for Android (2)-build and create a project

Source: Internet
Author: User

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

 

After the installation, the corresponding environment, we can start to create a cocos2d-x Android Project

Go to the cocs2d-x directory and open the create-android-project.bat in a text editor (if you double-click on Windows 7, some files may be created with insufficient permissions, resulting in project creation failure, you can add CD/d % ~ to the first line of this file ~ Dp0, right-click to run as Administrator)

Find the following definitions:

@echo off:: This script is used to create an android project.:: You should modify _ANDROIDTOOLS _CYGBIN _NDKROOT to work under your environment.:: Don't change it until you know what you do.cd /d %~dp0setlocal:: Check if it was run under cocos2d-x rootif not exist "�%\create-android-project.bat" echo Error!!! You should 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=D:\cygwin\binif not exist "%_CYGBIN%" echo Couldn't find Cygwin at "%_CYGBIN%" & pause & exit 4:: modify it to work under your environmentset _ANDROIDTOOLS=E:\android-sdk-windows\toolsif not exist "%_ANDROIDTOOLS%" echo Couldn't find android sdk tools at "%_ANDROIDTOOLS%" & pause & exit 5:: modify it to work under your environmentset _NDKROOT=E:\android-ndk-r8-windows\android-ndk-r8if not exist "%_NDKROOT%" echo Couldn't find ndk at "%_NDKROOT%" & pause & exit 6:: create android projectset /P _PACKAGEPATH=Please enter your package path. For example: org.cocos2dx.example:set /P _PROJECTNAME=Please enter your project name:if exist "�%\%_PROJECTNAME%" echo "%_PROJECTNAME%" exists, please use another name & pause & exit 7echo "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 targetsset /P _TARGETID=Please input target id:set _PROJECTDIR=�%\%_PROJECTNAME%echo Create android projectcall "%_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=%%A:: Resolve current dir to cygwin pathfor /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "�%"') do set _CURRENTDIR=%%A:: Resolve ndk dir to cygwin pathfor /f "delims=" %%A in ('%_CYGBIN%\cygpath.exe "%_NDKROOT%"') do set _NDKROOT=%%A     :: Throw away temporary env vars and invoke script, passing any args that were passed to usendlocal & %_CYGBIN%\bash --login "%_CYGSCRIPT%" %_CURRENTDIR% %_PROJECTNAME% %_NDKROOT% %_PACKAGEPATH% "windows"pause

Set _ cygbin = to the absolute path of cycgwin \ bin installation.

Set _ androidtools to the absolute path of Android SDK tools

Set _ ndkroot to the absolute path of Android ndk.

Modified and saved

Double-click the create-android-project.bat to start the project creation wizard

First, enter the package name (we recommend that you follow the naming rules of Android), such as com. Android. Test.

Enter the project name (do not enter the name of the existing folder. If the name is the same, it will be overwritten), such as testandroid, for example:

Then select the target ID,

It lists all versions of the SDK installed on the machine. We select 6, that is, the 2.3.2 SDK.

Go to the G: \ cocos2d-x directory and find a directory named testandroid, which contains three directories

Classes: stores the C ++ files of the default project.

Proj. Android is an Eclipse project of Android.

Resources resource file

Next, we will compile the created testandroid project.

Open cygwin, go to the testandroid/proj. Android directory, and enter./build_native.sh to start compiling, as shown in:

The final compilation is successful as follows:

After the compilation is successful, the so file (libgame. So) is generated directly under the directory testandroid \ proj. Android \ libs \ armeabi, and then imported to testandroid to eclipse for development.

 

 

 

 

 

 

 

 

 

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.