cocos2dx-2.x Eclipse Packaging APK

Source: Internet
Author: User
Tags goto python script


Prerequisite installation Environment: Java JDK Installation and environment variables, Python runtime environment

The COCOS2DX 2.2.2 version was created with a Python script, the script location: cocos2d-x-2.2.2\tools\project-creator\create_project.py;

Here you can write a batch file to facilitate creation; Createproject.bat

@echo off
: Label1
@cls
echo Welcome to use Python to create Cocos2d-x engineering
set/p project= Enter the project name you want to create:
set/p aid= Enter the Android version package ID you want to create:
echo the project name you entered is%project%
echo do
you enter the Android version package ID named%aid% Echo confirm the creation of the project? CHOICE/C 123/m "Confirm please press 1, cancel please press 2, or exit please press 3." "
Echo%errorlevel%
if%errorlevel%==1 goto label2
if%errorlevel%==2 goto label1
if%errorlevel%== 3 goto label3
: Label2
Echo is creating a project
... Python create_project.py-project%project%-package%aid%-language cpp
: label3
Pause

Run batch processing and create the project according to the prompts;

Welcome to create Cocos2d-x project by using Python
enter the project name you want to create: test02
Enter the Android version package ID you want to create: Com.hugh.test
The project name you entered is test02
Did you enter the Android version package ID named Com.hugh.test to confirm the creation of the project?
Confirm Please press 1, cancel please press 2, or exit please press 3. [1,2,3]?1
1
is creating the project ...
Proj.ios                : done!
Proj.android            : done!
Proj.win32              : done!
PROJ.WINRT              : done!
PROJ.WP8                : done!
Proj.mac                : done!
Proj.blackberry         : done!
Proj.linux              : done!
Proj.marmalade          : done!
Proj.tizen              : done!
New Project has been created in this Path:i:\cocosx\cocos2d-x-2.2.2\tools\proje
ct-creator/. /.. /projects/test02
Have fun!
Please press any key to continue ...

Then the Android project has been generated in the Cocos2d-x-2.2.2\projects\test02\proj.android directory

The C + + file classes for the project are in the classes directory

Need to put these C + + files in the JNI directory of the Android project

The main.cpp above is generated automatically when the project is generated and cannot be copied to the Win32 Project Main.cpp, which is related to Java JNI calls.

Next, all the classes that need to be compiled are added to the Android.mk file in the JNI directory.

Local_path: = $ (call My-dir)

include $ (clear_vars)

local_module: = cocos2dcpp_shared

Local_module_ FILENAME: = Libcocos2dcpp

local_src_files: = hellocpp/main.cpp \
                   ... /.. /classes/appdelegate.cpp \
                   ... /.. /classes/helloworldscene.cpp

Local_c_includes: = $ (Local_path)/.. /.. /classes

local_whole_static_libraries + = cocos2dx_static
local_whole_static_libraries + = Cocosdenshion_ Static
local_whole_static_libraries + = box2d_static
local_whole_static_libraries + = chipmunk_static
Local_whole_static_libraries + + cocos_extension_static

include $ (build_shared_library)

$ (call IMPORT-MODULE,COCOS2DX)
$ (call Import-module,cocos2dx/platform/third_party/android/prebuilt/libcurl)
$ (call import-module,cocosdenshion/android)
$ (call import-module,extensions)
$ (Call Import-module, external/box2d)
$ (call Import-module,external/chipmunk)

is to let the program know where our C + + files are placed, where we can change:

Local_src_files: = hellocpp/main.cpp \
Hellocpp/appdelegate.cpp \
Hellocpp/helloworldscene.cpp

In fact, do not change, the file on top of the classes directory originally have these documents, just to understand this truth;

The following need to COCOS2DX to the Android platform support code into our project, the file directory under COCOS2D-X-2.2.2\COCOS2DX\PLATFORM\ANDROID\JAVA\SRC;

The file in the Org directory is cocos2dx to the Android platform interface support, and we'll copy it to the SRC directory of the project:

It's almost ready for work here, so you can load the project with Eclipse now.

Of course the project will certainly error, compile parameters we have not yet set.

First we have to select the SDK for the platform

The editor then generates the Gen directory needed for the Android project.

Compared to the project just opened the appearance, is not generated a long absence of the Gen directory Ah, success in sight AH.

This time the project error is not much, we look at:

This is the project compile an error, see Bash should know that he is running the wrong compilation environment, Bash is Linux, we look at the configuration confirmed under

is not ah, running Linux under the script, we have to change it to the Windows platform corresponding on the line.

We change it to I:\cocosx\android-ndk-r9d\ndk-build.cmd this and compile it with ndk-build.cmd.

Here are a few parameters we need to match:

COCOS2DX parameter, set Cocos directory, I:\cocosx\cocos2d-x-2.2.2

Ndk_root parameter, set NDK directory, I:\cocosx\android-ndk-r9d

Ndk_module_path parameters, set NDK JNI need to call the directory, I:\cocosx\cocos2d-x-2.2.2;i:\cocosx\cocos2d-x-2.2.2\cocos2dx\platform\third_ Party\android\prebuilt

There's one more parameter left, directly above:

Well, the compilation environment has been set up, we clean up, see if there is no error:

Look, there's no more error. The next thing to deal with the resources, have not forgotten it.

The assets directory is not automatically generated under the Android project, and we have to manually create the directory and then handcuff the resources in the resource directory.

Well, then we'll compile it.

This is a long process.

See here, we need the library has been made up, and then packaged, there is nothing to talk about.

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.