Cocos2d-2.0-x-2.0.3 cross-compiled to Android

Source: Internet
Author: User

I used a cocos2d-2.0-x-2.0.3 before get a day is not successful today to download the latest ndk8 update the SDK again is actually successful, I don't know whether the tool version is correct or what is wrong. Here we will sort it out:

First, all the tools are configured, and then the. bash_profile file in cygwin is opened and the ndk path is added at the end.

Ndk_root =/cygdrive/C/android-ndk-r8d
Export ndk_root

2. Find the create-android-project.bat in cocos2dx. Open this file and there are three places to change.

Set _ cygbin = c: \ cygwin \ bin
Set _ androidtools = E: \ eclipse \ and SDK \ tools
Set _ ndkroot = c: \ android-ndk-r8d

Obviously, I won't say much about it.

3. After the modification is complete, run this file and follow the prompts to create the android project and replace the classes and resources in it with the one you wrote before.

4. open proj. in the android file build_native.sh, edit the new version of coco2.x, which is not the same as the previous coco1.x file. this change of X is not good for a long time. copy X and modify it.

 # Set paramsndk_root_local =/Cygdrive/C/Android-ndk- R8dcocos2dx_root_local =/Cygdrive/e/cocos2d-2.0-x-2.0.3Buildexternalsfromsource = Usage () {cat < Eofusage: $ 0 [Options] Build C /C ++ Native  Code using Android ndkoptions: - S build externals from source -H This  Helpeof}  While Getopts "S" option; Do          Case "$ Option"In S) buildexternalsfromsource = 1 ; H) usage exit 0 ; Esacdone #  Try  To get global variable  If [$ Ndk_root "AAA "! = "AAA" ]; Then ECHO "Use global definition of ndk_root: $ ndk_root" Ndk_root_local = $ Ndk_rootfi  If [$ Cocos2dx_root "AAA "! = "AAA"]; Then ECHO "Use global definition of cocos2dx_root: $ cocos2dx_root" Cocos2dx_root_local = $ Cocos2dx_rootfihelloworld_root = $ Cocos2dx_root_local/testcocos/ Proj. Android # Make sure assets is exist  If [-D $ helloworld_root/ Assets]; then RM -RF $ helloworld_root/ Assetsfimkdir $ helloworld_root / Assets # copy Resources  For File in $ cocos2dx_root_local/testcocos/Resources /* Do if [-d $ file]; then CP-RF $ File $ helloworld_root/assets Fi if [-F $ file]; then CP $ File $ helloworld_root/assets fidoneif [[$ buildexternalsfromsource]; then ECHO "Building external dependencies from source" $ ndk_root_local/ndk-Build-C $ helloworld_root $ * \ ndk_module_path =$ {cocos2dx_root_local }: $ {drivers}/cocos2dx/platform/third_party/Android/sourceelse echo "using prebuilt externals" $ ndk_root_local/ndk-Build-C $ helloworld_root $ * \ ndk_module_path =$ {drivers }: $ {cocos2dx_root_local}/cocos2dx/platform/third_party/Android/prebuiltfi 

In this section, we mainly configure some paths. You should take a good look at the green section. I have not configured this file for a long time and it has not been successful.

5. Configure Android. mk

Configure the local_src_files parameter. If you do not add any class libraries, you do not need to configure other parameters. Of course, you have created a small game to directly use the Cocos generated class. Therefore, you do not need to change this file.

Local_src_files: = hellocpp/Main. cpp \../../Classes/Appdelegate. cpp \../../Classes/helloworldscene. cpp

6. Run cygwin input CD $ ndk and press Enter.

Then locate your build_native.sh file location with the/cygdrive/file appended to it.

Enter./build_native.sh

Then your c ++CodeCompile it into an android class file and copy all the resource files.

7. Import this project to eclipse.

It may report Red Cross, for example, can not find the library file this is to the cocos2d-2.0-x-2.0.3 \ cocos2dx \ platform \ Android \ Java \ SRC lib package under the directory copy to the Project

If there are other errors, right-click the project and choose androidtools> fix project. Then, replace Java compiler with 1.6.

Also, do not change this sentence generated in the class.

Static {

System. loadlibrary ("game ");

}

Do not reportJava cocosdx couldn't load cocos2dx: findlibrary returned null

Then the operation should be successful.

 

 

 

 

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.