[Pin to top] cocos2d-x 2. X version Win32 window transplantation Android environment with only ndk super detailed Android environment

Source: Internet
Author: User
Tags win32 window android sdk manager

Welcome to repost: Please keep the source of the original article. Thank you.

Step 1: Integrate the android Development Environment

 

Here I will only introduce myeclipse eclipse.

 

Myeclipse 9.0 help -- myeclipse configuration center -- software -- browse software -- addsite

It's a little slow to open the configuration center. Please be patient.

As shown in:

If you extract the ADT, select Add form local folder. If you do not understand the pressure, use add form archive file.
1. The center command under the "help" menu: opens the workspace Center page.

2. Select the software tab,

3. Click "add site" to open the "add updates site" dialog box. Add ADT ......

4. After adding the ADT connection, click "OK" and return to the software tab. You can see that the ADT has been added,

5. The most important step is to select "android ddms" and click "+" on "add site" to add this plug-in to the "my software" list, add the plug-ins to be added in sequence as follows:

6. At last, we will see the "pending changes" area showing changes. Click "Apply" and the network cable will be slow.

There will be slow power. Please wait.

7. Restart myeclipse to install myeclipse successfully,

8. After restart, you will be prompted to install the android SDK manager. If there is an SDK manager, specify the SDK manager. Otherwise, you will click it to help you download the SDK manager.

 

9. After setting Android SDK manager to open myeclipse, choose winodw> preferences> Android> SDK location and select the android SDK root directory

 

10. test whether the development environment is successfully set up

File-> New-> Project-> Android Project

 

Step 2 How to port from the cocos2d-x source code to Android

 

Step 1:Configure the android project Builder


Use an editor like edit plus to open
Under the cocos2d-x directory
Create-android-project.bat and make changes.


Note: The paths in the above files must correspond to your own paths!


Step 2:Create an android Project

This step is achieved by running the cocos2d-x under the create-android-project.bat directory (in Windows ResourcesManagementYou can right-click the file and select to run it as an administrator ). For more information, run this file as an administrator ).

Then, the screen prompts you to enter the package name and project name. Note: If you enter an existing project name in version 2.0.2, the system will prompt you that the same name already exists and you are not allowed to create and exit. Note that this step is to run the file
Create-android-project.bat instead of anotherCreate-android-project.sh !!! ----- This file is used only later; otherwise, the entire process is messy !!!


 


-------> Project Name
-------> Pull to the end and fill in the ID corresponding to the version number, as shown in the above ID: 1 corresponds to "android 2.1"

Open the cocos2d-x more directory and you will find a helloworld directory as follows:



Step 3:Import Code and related resources

Now,
Copy the classes in your Win32 project to the current classes. Then copy the resources in your Win32 project to the current resources.
Note: The method for managing resources in versions 2.0.2 and 1.x has changed significantly. Of course, in the high version, management is more convenient and scientific.
Tip 2: copy and paste the file directly using the overwrite method. Also, you need to delete several files that may no longer be useful automatically generated by the system.


Step 4:Edit Android. mk and other files in the JNI folder

This step is complex and requires you to have a deep understanding of the locations and roles of application. mk and Android. mk in ndk programming. We will not discuss it here.

Because my example is a hello World program automatically generated by the system wizard, the process goes smoothly.
Modify the Android. mk file to the following format:
Local_path: = $ (call my-DIR)

Include $ (clear_vars)

Local_module: = game_shared
# Local_module_filename: = libgame

Local_src_files: = hellocpp/Main. cpp \
Http://www.cnblogs.com/Classes/AppDelegate.cpp \
Http://www.cnblogs.com/Classes/HelloWorldScene.cpp

Local_c_includes: = $ (local_path)/http://www.cnblogs.com/Classes \
$ (Local_path)/http://www.cnblogs.com/../cocos2dx \
$ (Local_path)/http://www.cnblogs.com/../cocos2dx/platform .\
$ (Local_path)/http://www.cnblogs.com/../cocos2dx/include \
$ (Local_path)/http://www.cnblogs.com/../cocosDension/include

Local_whole_static_libraries: = cocos2dx_static cocosdenshion_static cococos_extension_static

Include $ (build_shared_library)

$ (Call import-module, cocosdenshion/Android )\
$ (Call import-module, cocos2dx )\
$ (Call import-module, extensions)
My changes include:
1. commented out the local_module_filename: = libgame sentence.
2. Change the shared library name to game_shared. the following sentence in the eee21.java file must be modified accordingly:
System. loadlibrary ("game_shared ");

3. modified the header file reference part based on the location of my android project.

Local_c_includes: = $ (local_path)/http://www.cnblogs.com/Classes \
$ (Local_path)/http://www.cnblogs.com/../cocos2dx \
$ (Local_path)/http://www.cnblogs.com/../cocos2dx/platform .\
$ (Local_path)/http://www.cnblogs.com/../cocos2dx/include \
$ (Local_path)/http://www.cnblogs.com/../cocosDension/include

Where $ (local_path) is the JNI folder, so relative to this level of folder, the corresponding header file of your cocos2d-x system under which level of folder should be clear.

Step 5:Use eclipse to compile and package it into a real machine for testing


Use Create project from existing source under the new Android project:

File-> New-> project... in the subsequent "new project" dialog box, select Android-> Android project from existing code, as shown below:



The import project dialog box appears,Similar(From another instance:

Step 6:Use eclipse to compile and package it into a real machine for testing

Several problems may occur in the process.

The first one is

Org. cocos2dx. Lib. cocos2dxactivity cannot be found

Solution:
Copy *** \ cocos2dx \ platform \ Android \ Java \ SRC \ (*** to the cocos2d-x directory) to the SRC folder in your android Project
So there is another trouble, is not every creation to copy it, the answer is of course no, look at the method once and for all, positioning (cocos2d-x root directory) \ template \ Android \, open copy_files.sh in a text file, find the copy_src_and_jni () function, and add the following code:

CP-RF $ cocosjavalib_root/src $ app_dir/proj. Android

The second problem is that you still need to configure the Target Builder, or the compilation will crash.

Configure the ndk compiling environment
Right-click the simplegmae project and choose Properties> builders> New> program> OK.


Perform the following settings:
Location: select the ndk-build.cmd command under the ndk installation directory
Working directory: Select simplegame
Select refresh and configure it as follows:
Configure build options, as shown in
Modify the name of the newly created builder to ndk_builder. After the configuration is complete, click OK and click "up" to bring ndk_builder to the top.

The third problem is that it is best not to use a simulator for debugging. If you use a simulator to enable the simulator GPU test, and the version above 4.0 is required.

It's better to be a real machine.

Replies are virtues. Thank you, Yangcheng. | part of the alpaca is the copy of others' posts + self-organized

 

 

 

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.