Cocos2dx porting Android Platform

Source: Internet
Author: User

I have not been with the new site these days, asked me what to do, of course, to do this article to do, said the transplant is really troublesome ah, on-line test a variety of methods, do not know who is right who is wrong AH. But after I this three days of research finally succeeded, in order to let everyone less go some fruitless, I decided to write this article , novice, good look, don't waste time! Now I'm going to teach you all the problems I've encountered and a simple way (the way absolutely true, the Android part works for 3.0), and all the resources I've used. first of all, let's download the resources I gave you and download our tutorial.
about the issue of migration on-line version is broadly divided into using Cygwin and not to use, it is recommended that you do not use Cygwin, you download things do not say, download can not use more is the problem, many people is because this thing without confidence, The most important thing is NDK7 will not need to use it, our novice now use the version is definitely NDK7 later. There is also the use of create-android-project.bat this thing to create the project is also not used, From the beginning of the cocos2.2 version, it is recommended to use Python to create the project, but even if you want to use this thing, in the cocos2.2 of the main directory is not, since we do not have to do without. So let me just saythe whole idea. first use Python to build project engineering, under the Android project to copy some of our written Win32 project files, using the already configured to develop Android Eclipse Open Android project, in the project properties to configure some environment variables, Then build the. apk package and run the real machine! let's get started.
1, install python2.7.5. Download the software after the installation can be, the path to choose the default bar, anyway is not big, and then are the next choice.




2. Set the environment variable path to add the Python installation path to the environment variable. All operations are performed as shown in the figure.



Note that there is a semicolon behind the path, be sure to write it. 3, decompression cocos2d-x, of course, if you have some words will not be used. But it is best to put it in the root directory of the disk, my root directory in the e-disk. Copy the Python.bat to the E:\cocos2d-x-2.2\cocos2d-x-2.2\tools\project-creator folder. Run this batch, then enter the project name and the package ID name, and I will now transplant the Ninja Dart I wrote, all the operations.

Let's take a look at the success. No, the E:\cocos2d-x-2.2\cocos2d-x-2.2\projects is not much. You just created the contents of the project folder under the main folder.



4, we say a few important folders and files, are we will use. Classes folder will be put our source code, you write the source codes are put here, that is,. cpp and. h files, but there are two files to be aware of is main.cpp and Main.h, Wait a while you copy the time do not put main.cpp and main.h copy here, that copy to where, in fact you don't have to copy, main is the program's entrance, think of Win32 under how can put on the Android platform, The Android platform certainly has its own main, that is, the Android main in what position, I wait to say. OK, now copy the things you have written to this folder, remember to delete the classes folder you do not use the four files (otherwise your project is not getting bigger), for me the two files HelloWorld deleted, Appdelegate was replaced by me, Main.cpp and Main.h remember not to copy AH! Resource is the resources we use in our program, but don't copy the resources we use to this location. Under the Proj.android project, we saw three folders, and now we all go in and see what we need to do!

We first modify the Jni folder under the Android.mk, mainly to change the path of the files we used in the Classes folder, modify the place and the modified file, everyone according to my change on the line, It's really about letting the program know where our. cpp files are.


Then open the Hellocpp under JNI and see what you see, main.cpp, let's open it up and look.

This main.cpp is not completely different from Win32 under the CPP file, the first few times I was in the transplant project is my Win32 under the main copy to here, the result is always a compile error, and later found that, This is generated by Python, I guess the different platforms under the main write will not be the same. then open the Project Res folder, go inside to see what there is, is there a picture ah, that picture is we usually play mobile phone application when the icon displayed on the phone, here we can replace our own files. but the name should be the same as the original.


Then we see another folder under Project Engineering SRC, this folder is missing the Org folder, we have to copy one here, the path and so on.




Well finished these steps basically almost, now we are not a copy of the resource files, not anxious, we first build an Android development platform Eclipse. 5, now to install the JDK and JRE, install the two software I gave, by default, choose Next.
6, decompression Android-ndk-r9 and ANDROID_SDK, under ANDROID_SDK we need to use the Eclipse and SDK. Run Eclipse.

Press the icon. Download the API version of your phone, my Android phone version is 2.3, here I downloaded API8 and API10, we look at the number of their mobile phone version, download their own corresponding API. This process will take some time. Everyone waits patiently.



Then create a new virtual device. Step, the purpose is to run our program on the Win32, but we generally run on the real machine, this step is not necessary, if you want your program to test on the virtual machine, the following steps to do it, it is recommended to test on the real machine, so you can skip this step.



Then import our Android project, operation, choose the Android project when the choice is good, my directory is E:\cocos2d-x-2.2\cocos2d-x-2.2\projects\FirstGame\proj.android.



7, then look at our project directory, is not more than a few folders, one of which is the assets folder, where the side is empty, we put our program resources file in.


8, this step is very important, we have to configure the environment variables, we are optimistic about their installation path to add.





These three environment variables are: Add Cocos2dx, that is, cocos2dx extract the root directory; add Ndk_root, That is, the root directory of the NDK decompression; add Ndk_module_path, is the COCOS2DX root directory and such an eye e:\cocos2d-x-2.2\cocos2d-x-2.2; E:\cocos2d-x-2.2\cocos2d-x-2.2\cocos2dx\platform\third_party\android\prebuilt .




We can add the above three pictures, and the second picture is the cocos2d of the solution. The above configuration needs to be carefully configured, after the configuration is completed click OK, and then the following operation, we are not far from success!

9, because different people mobile phone version may be different, we here first say how to pack out for your own apk, while looking at the picture while talking.

Open the project directory under the Androidmanifest.xml file, where the figure underlined is the API version you want to package, different numbers for different Android version, you can change to their Android version of the corresponding API. when this is done, we go back to eclipse. Follow the instructions in the diagram.


If you see the second picture, prove that you succeed, and this time will be a bit long, if the previous error, just like me, is generally low API, so solve.

after compiling it, we need to pack it up. Attach a link to an article before you pack, and let's prepare a digital signature for the Andriod program. Then follow the instructions in the diagram .
then follow the instructions in the diagram .





See the top of this picture, you can wait for a moment in the path you set to see the packaged apk file, so that we have succeeded in the transplant, the project if there is any problem, is the configuration of the project variable after the problem, such as the program has errors, but clearly Win32 under normal AH, After you delete the item and re-import it again, and then don't look at that error and rebuild the project, basically the problem is solved. I run on the mobile phone, the final effect can not be shown to everyone, if you have any questions, welcome message, we discuss a piece.

Cocos2dx porting Android Platform

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.