Cocos2d-2.0-x-2.0.3 cross-compiled to android error Solution

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, Sort it out here:
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.Copy codeThe Code is as follows: # set params
NDK_ROOT_LOCAL =/cygdrive/c/android-ndk-r8d
COCOS2DX_ROOT_LOCAL =/cygdrive/e/cocos2d-2.0-x-2.0.3
Buildexternalsfromsource =
Usage (){
Cat <EOF
Usage: $0 [options]
Build C/C ++ native code using Android NDK
OPTIONS:
-S Build externals from source
-H this help
EOF
}
While getopts "s" OPTION; do
Case "$ OPTION" in
S)
Buildexternalsfromsource = 1

H)
Usage
Exit 0

Esac
Done
# Try to get global variable
If [$ NDK_ROOT "aaa "! = "Aaa"]; then
Echo "use global definition of NDK_ROOT: $ NDK_ROOT"
NDK_ROOT_LOCAL = $ NDK_ROOT
Fi
If [$ COCOS2DX_ROOT "aaa "! = "Aaa"]; then
Echo "use global definition of COCOS2DX_ROOT: $ COCOS2DX_ROOT"
COCOS2DX_ROOT_LOCAL = $ COCOS2DX_ROOT
Fi
HELLOWORLD_ROOT = $ COCOS2DX_ROOT_LOCAL/TestCocos/proj. android
# Make sure assets is exist
If [-d $ HELLOWORLD_ROOT/assets]; then
Rm-rf $ HELLOWORLD_ROOT/assets
Fi
Mkdir $ 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
Fi
Done
If [[$ buildexternalsfromsource]; then
Echo "Building external dependencies from source"
$ NDK_ROOT_LOCAL/ndk-build-C $ HELLOWORLD_ROOT $ *\
NDK_MODULE_PATH =$ {COCOS2DX_ROOT_LOCAL }:: {COCOS2DX_ROOT_LOCAL}/cocos2dx/platform/third_party/android/source
Else
Echo "Using prebuilt externals"
$ NDK_ROOT_LOCAL/ndk-build-C $ HELLOWORLD_ROOT $ *\
NDK_MODULE_PATH =$ {COCOS2DX_ROOT_LOCAL }:: {COCOS2DX_ROOT_LOCAL}/cocos2dx/platform/third_party/android/prebuilt
Fi

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.Copy codeThe Code is as follows: 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

It will compile your c ++ code into a class file for android and copy all the resource files and everything.

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.Copy codeThe Code is as follows: static {
System. loadLibrary ("game ");
}

The error "java cocosdx Couldn't load cocos2dx: findLibrary returned null" is not reported.
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.