This article is a small for original, reprinted please indicate the source.
I haven't updated the study articles of Cocos2d-x for a long time, recently I have done some things during college, and also made a few small Cocos2d-x programs, and search a lot of information on the Internet, finally, the SDK is successfully packaged into an APK and runs successfully on two Android phones.
The small for environment is Windows 8 + eclipse + cocos2d-x (2.2.1), there have been a lot of articles on how to package cocos2d-x projects online, and I found that these processes are not uniform. In this article, small for records only how small for is successfully packaged. I will not talk about setting up and configuring various environments. If you have any requirements, please read this article.
The text starts. (Tip: The following paths are absolute paths on small for computers. Please handle them yourself .)
Step 1: Create a project (cocos2d-x 2.2.1)
In the D: \ cocos2d-x-2.2.1 \ cocos2d-x-2.2.1 \ tools \ project-creator directory, press Shift and right-click, and select Open command window here (W )", in the command window, enter the create_project.py-project project_name-package com command for the new project. for. test-language cpp. In this way, a new project named project_name and package named com. for. test, mainly used for C ++ development projects .. under \ cocos2d-x-2.2.1 \ projects, you can see the folder for the new project, including the project files for each platform. As shown in
: Create a project command
: Create a project folder
Step 2: Copy Resources
This step is the easiest ,.
1. Create an assets folder in the proj. android folder under the project folder (project_name), and copy all Resources under the project folder to the assets folder.
2. Copy the org folder under the .. \ cocos2d-x-2.2.1 \ cocos2dx \ platform \ android \ java \ src folder to the .. \ project_name \ pro. android \ src folder.
Step 3: eclipse import Project
Eclipse file-> import-> Android-> Existing Android Code Into Workspace, and then select the .. \ cocos2d-x-2.2.1 \ project \ project_name. In this case, eclipse reports an error.
Step 4: Modify the file
1. Modify the build_native.sh file in the project folder, as shown in. (The content in the first red box is the NDK path. Note that use EditPlus to modify the content, when saving the file, choose File Format> change file format> Unix/Mac OS x> OK and save the file. Otherwise, an error occurs if the encoding is incorrect ).
2. Modify the. mk File
Open Android in the jni folder under eclipse. mk, under LOCAL_SRC_FILES, add the rules to the various types of files created in development by partners according to the existing rules. cpp file or. c file (NOTE: When sqlite3 is used, there is a Shell. c file, because it contains the main function, it cannot be added here .). Add the following code at the end of the file:
3. Modify the environment
In eclipse, right-click the project and choose "properties"> "C/C ++ Build"> "Use default build commend"> "E: \ Eclipse \ sdk \ android-ndk-r9d-windows-x86_64 \ android-ndk-r9d \ ndk-build.cmd (note, depending on the situation)-> Apply-> OK.
Step 5: Run the Android Program (Run As Android Application)
After running, a project_name.apk is generated under the folder of pro. android/Bind. This is our final goal. Copy it to the Android real machine for testing and run it successfully. Finally finished writing, hey, the first packaging time, spent two days, at that time really think eclipse + Cocos2d-x is pitfall ah, step by step for the pit. Just get used to it, huh, huh. Today is a happy holiday for all of us. Small for started looking for a job, and it was a lot of pressure. I took a written test last time. I did not know much about the test, and the Foundation was not solid enough. Alas, come to a large company to accept me. But now, small for is different from before. I don't want to go to other places. After all, Chongqing has my loved ones and people I love. Just try an interview with several big companies. Haha! Thank you for your consideration. Thank you for your understanding and criticism!