Cocos2d-x 3.2 project source code package from Mac to Android tutorial

Source: Internet
Author: User

Cocos2d-x 3.2 project source code package from Mac to Android tutorial
After using Xcode to write the source code of a project, how can we import it to Android phones? Next I will give you a step by step to explain: First, we open the terminal, cd to the Cocos2d-x 3.2 folder (note that not you write the project folder, but the official project source code. Http://cn.cocos2d-x.org/download/), and then execute the following command:./setup. pyAt this time, you will see it in the Check NDK, Android_SDK, ANT path. If you have not set it before, execute the following command:Vi/Users/donliu/. bash_profile note !!! The path after vi is yours. After executing the first command, he will tell you the address and copy and paste it directly. After the execution, we can see that we opened a file with vi. Now we add the NDK, Android_SDK, and ANT paths to the file. Of course, we need to download some resources before joining the website. Some resources may need to be moved over the wall (What do you do not want to go over the wall? You will not be a programmer !). ANT: http://ant.apache.org/Android_SDK:https://developer.android.com/sdk/index.html? Hl = iNDK: replace blockchain with r9c. After the download is complete, import the code to the file opened with vi (What do you do not use vi ?! You won't use vi as a programmer! Google !) :

Export ANDROID_SDK_ROOT =/Users/donliu/Desktop/cocos2dxandroid/adt-bundle-mac-x86_64-20140702/sdk

Export NDK_ROOT =/Users/donliu/Desktop/cocos2dxandroid/android-ndk-r9c

Export ANT_ROOT =/Users/donliu/Desktop/cocos2dxandroid/apache-ant-1.9.3

Note that the equal sign is followed by your own path. (Note that the path behind ANDROID_SDK_ROOT is not adt, but the sdk in it ). Okay, so our previous work is finished. You don't need to repeat the above steps when you package the package later (we know it! Let's talk about how to compile it !). OKOK. Do not rush. Next, open eclipse in the SDK, File, Import in the upper left corner, and Existing Android Code Into Workspace in Android. On the right side of Browse, select the project source code folder you wrote, enter the proj. android folder in it, click Open, and never select Copy projects into workspace to Finish directly. This is where we can see the Project name Project in the Package Explorer on the left. But there is a red cross on it. We should first kill the Red Cross because of obsessive-compulsive disorder. Find the project source code folder in the Finder, choose cocos2d> cocos> platform> android> java> src> org> cocos2dx to copy the entire lib folder to proj under the project source code folder. android-> src-> org-> cocos2dx. Let lib and cpp appear in a directory. OK, we turn off the Finder, switch back to eclipse, right-click Refresh on the entire project, and then the magic scene appears: The Red Cross disappears! The exclamation point. Okay. We started to ignore the exclamation mark (What about obsessive-compulsive disorder? Nima, when you write a program, you get rid of every Warning? What? Yes? Okay, let's kneel down .) Next, open the jni folder, find Android. mk, double-click it, and one line on the right is displayed:

LOCAL_SRC_FILES

We will change the code behind it. By default, only:

Hellocpp/main. cpp \

.../../Classes/AppDelegate. cpp \

.../../Classes/HelloWorldScene. cpp

But obviously, you can't have only a few. cpp in Classes. (why did you write something in HelloWorldScene? Okay .), So we changed it to all. cpp under your Classes (note not to write. h). The format should be the same as what he gave. For example, mine is:

LOCAL_SRC_FILES: = hellocpp/main. cpp \

.../../Classes/AppDelegate. cpp \

../Classes/Select. cpp \

../Classes/Game. cpp \

../Classes/Wall. cpp \

../Classes/Ball. cpp

Save the changes. Next, we will add a Resource. Open the source code folder of your project in the Finder, and copy all resources in the Resource to the proj. android-> assets folder (if this folder is not available, create one ). Similarly, switch back to eclipse and refresh it. Then, open Application. mk in the jni folder and change its content to the following:

APP_STL: = gnustl_static

APP_CPPFLAGS: =-frtti-DCC_ENABLE_CHIPMUNK_INTEGRATION = 1-DCOCOS2D_DEBUG = 1-std = c ++ 11-fsigned-char

Remember to save it! I once called it for half a day, but the result was not saved! Crying ...... OK. The most critical step is to compile! Open the terminal, cd to the project folder, and execute the following command: cocos compile-p android press enter to start compilation. The compilation process will be slow. You can have a cup of coffee and wait ...... If

[Armeabi] Compile ++ thumb: cocos2dcpp_shared <= main. cpp

[Armeabi] Compile ++ thumb: cocos2dcpp_shared <= AppDelegate. cpp

In this case, the error must be caused by an error in your Android. mk file. Check the error.

If there is no error after the check, take a closer look at the error prompt and change the corresponding cpp source code. I have encountered a hard time remembering it.

After the terminal is running, it is unnecessary to find the last error, as long as there is one:

[Armeabi] Install: libcocos2dcpp. so => libs/armeabi/libcocos2dcpp. so

If this one exists, the compilation is successful. Switch back to eclipse, refresh the project, and check whether libcocos2dcpp is available in libs-> armeabi. so, if yes, right-click the project on your computer, Run As-> Android Application, and select your mobile phone to start testing!


You may have never packaged an APK before. Here we will talk about how to package it into an APK.

Right-click the project, Export, Android-> Export Android Application, and click Next. By default, the right-click Project is used to continue Next. Here is a Keystore selection. For the first package, select Create new keystore, then Browse a random folder (where should I remember the nonsense), fill in the password and confirmation, and click Next.

Next, let's fill it out by yourself. Note that the value of Validity must be greater than 25 and Next.

Not to mention the rest. Complete the application name and click Finish. The generated APK can be directly installed on the Android phone.

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.