Cocos2d-x is a multiplatform game framework. It is a reimplementation of Cocos2D for iPhone in C++.

The main idea about it is that you are going to write plain old C++ code and that code will run on both Android (via JNI thanks to the NDK) and iPhone. It also has support for Win32, WoPhone and some other platforms, check them out on the Cocos2D-X website.

The zip that you can download from the project’s website includes wizards/helpers for creating a new project for each of the supported platforms, but it doesn’t have a wizard that will let you specify what platforms do you want to work on and then generate everything from one shot.

I took some time and figured out a way to manually create one of these hybrid projects for Android and iOS. This article is actually based on an edited version of an older article of mine which addressed an older version of cocos2dx and mainly assumed that you were using Xcode 3.


Prerequisites

This tutorial uses the cocos2d-1.0.1-x-0.11.0 release. I will try to keep the guide updated as new versions are launched, but I could really use your help in the comments section in case I miss something specific to a new version.

The first thing you need to do is set up your system paths. This is what my .bash_profile looks like:

export ANDROID_NDK_ROOT=~/Development/AndroidNDK/
export COCOS2DX_ROOT=~/Projects/Cocos2d-x/
export NDK_ROOT=~/Development/AndroidNDK/
export ANDROID_SDK_ROOT=~/Development/AndroidSDK/
export PATH=$PATH:$ANDROID_NDK_ROOT

Some parts of Cocos2D-x reference ANDROID_NDK_ROOT, some NDK_ROOT. Be as it may, we define both of them and add the path to the system path.

In order to create the hybrid project we will follow the steps below:

  1. create the iPhone project
  2. create the Android project
  3. merge the Android project into the iPhone project

Creating the iPhone project

Cocos2D-x provides a bunch of templates for both XCode3 and 4 that will create the project along with all that is needed. We will use the Xcode 4 templates in this tutorial, although I like the Xcode3 templates better.

To install the templates fire up a Terminal, navigate to the Cocos2D-x directory:

cd $COCOS2DX_ROOT

In order to install the templates you need to have root privilege, so we will call:

sudo ./install-templates-xcode.sh

The terminal will then ask you what to install:

cocos2d-x template installer
select the template version to install
3 for xcode3
4 for xcode4
input nothing for all

If you have both XCode3 and 4 installed, just hit enter, otherwise hit 4 for the XCode 4 templates.

Once you’ve done this, start up XCode and create a new project:

I called my new project SimpleGame so the next few examples will feature this name.

You should build and run your project now to make sure that it works properly.

A few considerations about the iPhone project

The main difference between creating an iPhone project first as opposed to an Android project is that the iPhone template will copy over and integrate the some of the Cocos2D-x framework in the project’s structure, while Android will just keep a reference to it. Android projects by default are designed to be kept inside the Cocos2D-x folder.

Creating the Android project

In the terminal get to the Cocos2D-x folder and type the following:

$COCOS2DX_ROOT/create-android-project.sh

You will then be asked for a package path:

Input package path. For example: org.cocos2dx.example

Use something like org.cocos2dx.simplegame.

Then the wizard will ask you for the Android version that you want to support. Android 2.1 is a good choice:

Now cocos2d-x suppurts Android 2.1-update1, 2.2, 2.3 & 3.0
Other versions have not tested.
Available Android targets:
[...]
id: 5 or "android-7"
Name: Android 2.1-update1
Type: Platform
API level: 7
Revision: 2
Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
[...]
id: 7 or "android-8"
Name: Android 2.2
Type: Platform
API level: 8
Revision: 2
Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
[...]
id: 9 or "android-9"
Name: Android 2.3
Type: Platform
API level: 9
Revision: 1
Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854
[...]
input target id:

To select Android 2.1 in this case, type 5 and hit enter (the numbers vary based on your installed Android SDK versions). You will then be asked for the project name:

input your project name:

Type SimpleGame and hit enter. A new folder will be created with this name in the Cocos2D-x directory and the project files will be copied inside.

Careful if you created the iPhone project and saved it in the Cocos2d-x folder – it may get overwritten. The best bet is to make sure that no other folders with the same name exist in here.

And to see if it really worked you can make a build:
$COCOS2DX_ROOT/SimpleGame/android/build_native.sh

If it all works out without any errors we are now ready to move to the last step.

Merging the Android project into the iPhone project

When we will be done with this chapter, the structure of the game should be something like this:

First, we are going to create a makefile to help us test if the Android build script is still working properly.

Fire up the editor of choice and create a file named makefile in the android subdirectory of the Cocos2d-x/SimpleGame folder:

nano $COCOS2DX_ROOT/SimpleGame/android/makefile

Type in:

clean:
rm -rf libs/
rm -rf obj/

To exit and save, hit Ctrl+X, type Y, and then hit Enter. From now on, calling make clean in the Android directory will delete the already compiled binaries.

Do it now to clean up the compiled libraries from the previous step:

cd $COCOS2DX_ROOT/SimpleGame/android
make clean

Copying over the Android specific files to the main project

The actual merging will consist of copying over some of the folders from the Android directory, adjusting some values in the build_native.sh script and modifying a file from the iPhone project.

First, copy the android folder from $COCOS2DX_ROOT/SimpleGame/android/ to the iPhone project directory, next to the ios folder (the final path would be SimpleGame/SimpleGame/android/).

Second, copy the Android.mk file from $COCOS2DX_ROOT/SimpleGame/Classes/ to SimpleGame/SimpleGame/Classes.

Third, copy the Android.mk file from $COCOS2DX_ROOT/cocos2dx/ to SimpleGame/SimpleGame/libs/cocos2dx/.

Fourth, copy the android folder from $COCOS2DX_ROOT/CocosDenshion to SimpleGame/SimpleGame/libs/CocosDenshion/.

Finally, copy the platform folder from $COCOS2DX_ROOT/cocos2dx/platform to SimpleGame/SimpleGame/libs/cocos2dx/.

Sure, this will copy over the win32, marmalade, linux and other folders as well, but unless you want to hunt and peck through the folders to figure out what you need and what you don’t, just trust me on this one and copy all of them over.

Editing the Android makefile paths

Then edit the android/build_native.sh file and update the following paths:

# set params
COCOS2DX_ROOT=../libs/cocos2dx
GAME_ROOT=../
GAME_ANDROID_ROOT=$GAME_ROOT/android
RESOURCE_ROOT=$GAME_ROOT/Resources

Next, open up the android/jni/Android.mk file and make it look like the following:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

subdirs := $(addprefix $(LOCAL_PATH)/../../libs/,$(addsuffix /Android.mk, \
           cocos2dx \
           CocosDenshion/android \
	))
subdirs += $(LOCAL_PATH)/../../Classes/Android.mk $(LOCAL_PATH)/helloworld/Android.mk

include $(subdirs)

 

Next, open up the android/jni/helloworld/Android.mk file and make it look like the following:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game

LOCAL_SRC_FILES := main.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../libs/cocos2dx \
                    $(LOCAL_PATH)/../../../libs/cocos2dx/platform \
                    $(LOCAL_PATH)/../../../libs/cocos2dx/include \
                    $(LOCAL_PATH)/../../../Classes

LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/$(TARGET_ARCH_ABI)) \
                -lcocos2d -llog -lgame_logic

include $(BUILD_SHARED_LIBRARY)

What we have done is basically update the relative paths to match our folder structure — instead of going all the way to the folder above our project folder (the old cocos2dx installation directory), we go to the root of our project and then enter the libs folder.

Finally, open up the Classes/Android.mk file and update the paths once more to match the following:

LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_logic

LOCAL_SRC_FILES := AppDelegate.cpp \
                   HelloWorldScene.cpp

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../libs/cocos2dx \
                    $(LOCAL_PATH)/../libs/cocos2dx/platform \
                    $(LOCAL_PATH)/../libs/cocos2dx/include \
                    $(LOCAL_PATH)/../libs/CocosDenshion/include \
                    $(LOCAL_PATH)/../libs/cocos2dx/lua_support 

LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../android/libs/$(TARGET_ARCH_ABI)) \
                -lcocos2d -lcocosdenshion \
                -L$(call host-path, $(LOCAL_PATH)/../libs/cocos2dx/platform/third_party/android/libraries/$(TARGET_ARCH_ABI)) -lcurl
            
include $(BUILD_SHARED_LIBRARY)

Now go to the android folder and type in the terminal

make clean

This will delete all the previously compiled libs and objs so they can be rebuilt by the build script. This is important! If you don’t clean up the already built libraries they won’t be deleted and the build script will complain that there’s “no rule to make target”.

Finally, type build_native.sh from the android folder in the terminal and have it successfully compile.

Each and every time you want to deploy an APK to an Android device (or virtual device) make sure you clean the project from inside Eclipse (Go to Project > Clean) and then right click the project and Run As > Android Application

Cleaning the project will force Eclipse to refresh the bundle files and take into account the newly compiled code when creating the game APK.

Optional: cleaning the platform folder

The platform folder inside the libs/cocos2dx is somewhere around 115MB. Unless you want to pollute your versioning system with a lot of unnecesssary files, I suggest you clean up that folder before committing.

To do that, open up the libs/cocos2dx/platform path and delete all the folders except for ios, android and third_party. You should NOT delete any of the files however.

Next, enter the libs/cocos2dx/platform/third_party folder and delete all the existing folders except for android and ios. This should clear you up about 50 MB of space.

Share this article

Tagged on:             

49 thoughts on “Creating an iPhone and Android Cocos2D-x hybrid project (updated)

  • Pingback: Creating an iPhone and Android Cocos2d-x hybrid project

  • February 3, 2012 at 12:13 am
    Permalink

    Hello I´m following the tutorial but I had some problem executing $COCOS2DX_ROOT/SimpleGame/android/build_native.sh

    Show a lot of errors with CCConfiguration.h

    This is one example:
    /Users/MyUser/Projects/Cocos2d-x/SimpleGame/android/jni/../../../cocos2dx/CCConfiguration.cpp:90: error: ‘glGetString’ was not declared in this scope

    And this is the last error:
    make: *** [/Users/MyUser/Projects/Cocos2d-x/SimpleGame/android/obj/local/armeabi/objs-debug/cocos2d/CCConfiguration.o] Error 1

    Do you have some idea why is occurring this?

    Thanks in advance!

    Reply
    • February 3, 2012 at 2:25 am
      Permalink

      I have resolved that just trying with NDK of the MacOSX because I was trying with Windows NDK instead.

      Now I have a problem because I want to use Box2D and I don´t know how carry that.

      Any suggestion??

      Thanks in advance.

      Reply
      • February 3, 2012 at 1:17 pm
        Permalink

        You will need to manually copy the Box2D folder next to the cocos2dx folder inside the libs directory and make the changes from this guide:
        http://gameit.ro/2011/08/creating-a-cocos2d-x-box2d-android-project/

        Basically you should open the .mk files and add the path to the Box2D in the specified spots (the path to the Box2D directory will be similar to the path to the cocos2dx directory inside the libs folder)

        Reply
  • February 7, 2012 at 12:37 am
    Permalink

    Thanks a lot for this brillant tutorial! I have got the following error when I compile:

    *** No rule to make target `jni/../../libs/cocos2dx/platform/CCFileUtils.cpp’, needed by `obj/local/armeabi/objs-debug/cocos2d/platform/CCFileUtils.o’. Stop.

    Any idea to solve this problem? Thanks !!

    Reply
    • February 7, 2012 at 12:44 am
      Permalink

      Looks like the file’s not there. Have you copied the platform folder into the cocos2dx folder?

      It’s this step:
      Finally, copy the platform folder from $COCOS2DX_ROOT/cocos2dx/platform to SimpleGame/SimpleGame/libs/cocos2dx/.

      You should try navigating to android/jni and typing out ls ../../libs/cocos2dx/platform/. If you’re not seeing the CCFileUtils.cpp file there it means that you need to copy the platform folder over.

      Reply
      • February 7, 2012 at 1:29 am
        Permalink

        Thanks for your very quick reply! Actually, I had a doubt on the location where to copy the folder: do I have to replace the platform folder which is already here? (containing some CC files and an iOS folder) I initially thought that I had to copy $COCOS2DX_ROOT/cocos2dx/platform/android to SimpleGame/SimpleGame/libs/cocos2dx/platform/android… Do you confirm that this is wrong and that I have to replace the already existing platform folder? Thanks a lot for your help!

        Reply
        • February 7, 2012 at 2:32 am
          Permalink

          You can safely replace that folder with the one from the cocos2dx root location as it already contains the ios files as well.

          Reply
          • February 7, 2012 at 2:44 am
            Permalink

            Thanks! I am blind…I didn’t see that this folder contains an iOS folder… Last question (I hope): I now get the following error:

            SharedLibrary : libgame_logic.so
            /Applications/Android/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lcurl
            collect2: ld returned 1 exit status
            make: *** [obj/local/armeabi/libgame_logic.so] Error 1

            Any idea? Thanks again!

  • February 8, 2012 at 2:07 pm
    Permalink

    Hi again !

    I am now trying to convert a full game developed with XCode to an hybrid project in order to be able to port it to Android (via Eclipse). Nevertheless, I have got some problems to do this and I asked the following question on stackoverflow (and made some advertising for your article/blog :)): http://stackoverflow.com/questions/9192058/cocos2d-x-how-to-port-to-android-via-eclipse-a-cocos2s-x-project-developed-wi Are you able to answer this question ? Thanks again for your great tutorial!!

    Reply
    • February 8, 2012 at 2:30 pm
      Permalink

      Replying here as well so people can find the answer faster:

      From the looks of it you need to add your custom created files to Classes/Android.mk in the LOCAL_SRC_FILES section like this:

      LOCAL_SRC_FILES := AppDelegate.cpp \
      HelloWorldScene.cpp \
      IntroMenu.cpp \
      GameLayer.cpp \
      ScoreManager.cpp

      You need to do this in order to let the android build file know about the new files which need to be included in the build process.

      You will need to do this, afaik, for each new source file that you add to the project.

      Reply
    • February 10, 2012 at 2:09 am
      Permalink

      Thanks for your answer on cocos2d-x.org ; I did what you recommend and…same error! Have a look to my answer on Cocos2d-x forum… This is driving me crazy!

      Reply
  • February 11, 2012 at 5:59 am
    Permalink

    Thanks man, It’s a great tutorial!

    Reply
  • February 13, 2012 at 11:28 pm
    Permalink

    What version of Eclipse are you using? I can’t get any of the android projects produced with create-android-project.sh to import as a project into Eclipse (using select root directory, no projects are recognized). Currently running Mac 10.6 with Eclipse Classic 3.7.1 as 64-bit.

    Reply
    • February 14, 2012 at 12:43 am
      Permalink

      I think it was something similar, I don’t have access to it right now.

      Nevertheless, you should be choosing the android folder as the project root in the import projects screen, if I recall correctly.

      Reply
      • February 14, 2012 at 8:09 pm
        Permalink

        Yup, just got it working. Instead of trying to import an existing project, you have to go to New Project > Android > and then choose existing code (2nd option).

        So now that I have the app in Eclipse, it can’t find my images. I’ll go back and make sure I’m pointed to the right Resources folder. Can android traverse directories to find my images in sub-folders?

        Reply
        • February 14, 2012 at 8:33 pm
          Permalink

          The images should be visible as soon as you run build_native.sh.

          That script (along with building the lib files) should copy the contents of the Resources folder from a level above the android folder to the Resources from within the android folder.

          Reply
  • February 21, 2012 at 4:36 pm
    Permalink

    hi, first thank you for your great tutorials.
    but i have come across a problem.
    i use maxos 10.7 and java version is 1.6,ndk version is 7.
    but when i copy all the android relatived files to ios project.
    when i build the ios project , i get a jni.h can’t be found error.
    i have struggled with this problem for a long time,
    i hope you can help me to figure it out.
    thank you very much!

    Reply
    • February 21, 2012 at 4:45 pm
      Permalink

      when i use build_native.sh ,then i get a following error message:

      make: *** No rule to make target `game_shared’, needed by `ndk-app-local’. Stop.

      Reply
      • February 21, 2012 at 4:51 pm
        Permalink

        That’s very weird as I can’t find any reference to game_shared in Cocos2D-x. Can you perform a string search and see where it’s coming from?

        Jump to your project folder and run

        grep -ir game_shared .

        Reply
        • March 9, 2012 at 6:05 pm
          Permalink

          hi, I have a same problem.
          grep -ir game_shared says:
          ./android/jni/Application.mk:APP_MODULES := cocos2dx_static cocosdenshion_shared game_shared

          whats wrong with this?

          Reply
      • March 10, 2012 at 9:26 pm
        Permalink

        Here is the flaw: when you modify android/jni/helloworld/Android.mk file, this line is not correct:

        LOCAL_MODULE := game

        Replace ‘game’ with ‘game_shared’, and it should work fine now.

        Reply
        • March 10, 2012 at 9:44 pm
          Permalink

          Thanks! Looks like there were some serious changes in the Android.mk files in the last Cocos2D-x version. I will update the post accordingly after I get the chance to check things head to toe.

          Reply
          • March 10, 2012 at 11:16 pm
            Permalink

            After that I’ve found another flaw, but this time I couldn’t fix it :( ;).

            Message says ‘cannot find -lcocos2d’. It seems it can’t find cocos2d module, defined at android/jni/helloworld/Android.mk and Classes/Android.mk

          • April 11, 2012 at 9:48 am
            Permalink

            I have the exact same error that Iturri mentions below:

            “cannot find -lcocos2d
            collect2: ld returned 1 exit status
            make: *** [obj/local/armeabi/libgame_shared.so] Error 1″

            Any update on this error?

          • April 26, 2012 at 5:15 pm
            Permalink

            It seems this is the error I am getting, though having LOCAL_MODULE := game_shared will compile the code, it gives me a

            No rule to make target `game_shared’, needed by `ndk-app-local’. Stop.

            Changing it to := game will give me this same issue: cannot find -lcocos2d:

            /devtools/android-ndk-r7c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lcocos2d
            collect2: ld returned 1 exit status
            make: *** [obj/local/armeabi/libgame_shared.so] Error 1

            I guess this is the end of the line? Or has anyone managed to get around this bugger?

  • March 1, 2012 at 2:42 am
    Permalink

    Great tutorial you’ve got here, but I am running into a bit of a problem here with running the makefile that is made. No matter what I do, when I try to call make clean I always get an error that says “makefile:2: *** missing seperator. Stop.” and I am writing it exactly how you have it. Is there anything you suggest that I do, because I’ve looked everywhere and I am stumped :(

    Reply
    • March 1, 2012 at 5:59 pm
      Permalink

      Make sure you leave an empty line at the end of the file and that the rm commands are indented.

      WordPress might have eaten some of my markup when I wrote the post.

      Reply
    • March 5, 2012 at 12:43 pm
      Permalink

      Try to use “tab” key before these two lines.

      rm -rf libs/
      rm -rf obj/

      Reply
      • March 14, 2013 at 5:57 pm
        Permalink

        I have been having the same issue.
        I have tried placing tabs before each rm line and an emply line after them. Still getting the same message. Anything else to do?

        Reply
  • March 27, 2012 at 1:29 am
    Permalink

    Hello, I have the same problem (cannot find -lcocos2d) with cocos2d-1.0.1-x-0.12.0.
    Any way to fix it?
    Thanks

    Reply
    • March 27, 2012 at 3:21 am
      Permalink

      May be problem is related to new directory structure under …/platform/third_party/android/…

      Reply
  • April 19, 2012 at 11:13 pm
    Permalink

    using cocos2d-1.0.1-x-0.12.0. and got -lcocos2d too.

    btw im really new to cocos2dx (just switch from cocos2d since new project need to export on both ios and android) but it seem to me that isn’t it easier to copy xcode project’s content to android folder created by .sh?

    sorry for my English.

    Reply
  • April 20, 2012 at 5:13 am
    Permalink

    Great tutorial , i have 2 questions.

    After i have done this 4 steps.

    First, copy the android folder from $COCOS2DX_ROOT/SimpleGame/android/ to the iPhone project directory, next to the ios folder (the final path would be SimpleGame/SimpleGame/android/).
    Second, copy the Android.mk file from $COCOS2DX_ROOT/SimpleGame/Classes/ to SimpleGame/SimpleGame/Classes.
    Third, copy the Android.mk file from $COCOS2DX_ROOT/cocos2dx/ to SimpleGame/SimpleGame/libs/cocos2dx/.
    Fourth, copy the android folder from $COCOS2DX_ROOT/CocosDenshion to SimpleGame/SimpleGame/libs/CocosDenshion/.
    Finally, copy the platform folder from $COCOS2DX_ROOT/cocos2dx/platform to SimpleGame/SimpleGame/libs/cocos2dx/

    you say edit 3 files and make clean and ./build_native.sh ,then open eclipse import android project from source.
    1.android/build_native.sh
    2.android/jni/helloworld/Android.mk
    3.Classes/Android.mk
    4.and Now go to the android folder and type in the terminal
    make clean

    Now i have 2 questions:
    first question:
    1.android/build_native.sh
    2.android/jni/helloworld/Android.mk
    3.Classes/Android.mk
    4.and Now go to the android folder and type in the terminal
    make clean
    this android folder means $COCOS2DX_ROOT/SimpleGame/android/ or SimpleGame/SimpleGame/android/

    second question:
    the android folder imported to eclipse means $COCOS2DX_ROOT/SimpleGame/android/ or SimpleGame/SimpleGame/android/

    thanks!

    Reply
    • April 26, 2012 at 5:30 pm
      Permalink

      Sky – I believe it is meant to be implicit that SimpleGame/SimpleGame/android/ folders anytime the COCOS2DX_ROOT is not used. I did mention that this could be a little more clear in my post below.

      Reply
  • April 26, 2012 at 4:08 pm
    Permalink

    I’m getting a different no rule error than described in the two above. I did run make clean in the android folder.

    make: *** No rule to make target `jni/../../CocosDenshion/android/Android.mk’. Stop.

    I think making the directory paths a bit more clear, by using PROJECT/Path/To/ would be nice. There are many ‘android’ folders, and other folders of the same names- that said I just went with the assumption the paths implicitly start from PROJECT.

    Any known cause to this no rule?

    Reply
    • April 26, 2012 at 4:32 pm
      Permalink

      I managed to figure out that I needed to add /libs/ inside PROJECT/android/jni/Android.mk


      subdirs := $(addprefix $(LOCAL_PATH)/../../libs/,$(addsuffix /Android.mk, \
      cocos2dx \
      CocosDenshion/android \
      ))

      However now the Android NDK is aborting on me, haven’t yet figured that out – perhaps it does not like that I added ‘libs’ to that path? I’m still trying to investigate this but not exactly on home-turf.

      Reply
    • April 26, 2012 at 4:52 pm
      Permalink

      Well, that last issue was my fail, apparently something went wrong while copying over the platforms folder; I got a bit further along but am not sure what this means?

      /devtools/android-ndk-r7c/toolchains/arm-linux-androideabi-4.4.3/prebuilt/darwin-x86/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lcocos2d
      collect2: ld returned 1 exit status
      make: *** [obj/local/armeabi/libgame_shared.so] Error 1

      Reply
  • May 3, 2012 at 12:48 pm
    Permalink

    Hello,
    first of all thanks for the tutorial but im having several problems with it.
    I’m working with the latest cocos2dx and xcode versions (on a mac, obviously).

    Everything is clear to me until the files should be copied. These files just don’t exist:

    Classes/Android.mk
    jni/helloworld/Android.mk

    should they be created, containing your mentioned code?

    Until now i’m running into errors whil executing build_native.sh (my NDK works just fine for android only projects)

    What am i doing wrong?
    Fell free to contact me if you need to know more.

    cheers
    Maximilian

    Reply
  • June 28, 2012 at 2:19 pm
    Permalink

    Great work, clw!

    I post this entry mainly because I want to receive updates with new posts and comments.

    By the way, it would be very helpfull too, if you’d post links to the libraries used (AndroidNDK/SDK) also with its respective versions

    Regards

    Reply
  • September 16, 2012 at 2:43 pm
    Permalink

    I find some differences with cocos2d-x 2.0.2:

    1) In $COCOS2DX_ROOT/SimpleGame/android/build_native.sh ==> “android” folder doesn’t exists. New name is “proj.android”

    2) $COCOS2DX_ROOT/SimpleGame/Classes/Android.mk ==> This file doesn’t exists

    3) android/build_native.sh ==> some params have changed:
    DIR=”$( cd “$( dirname “${BASH_SOURCE[0]}” )” && pwd )”
    # … use paths relative to current directory
    COCOS2DX_ROOT=”$DIR/../..”
    APP_ROOT=”$DIR/..”
    APP_ANDROID_ROOT=”$DIR”

    4) android/jni/Android.mk seems different (I don’t know if is only a syntax difference):
    LOCAL_PATH := $(call my-dir)
    include $(CLEAR_VARS)
    LOCAL_MODULE := game_shared
    LOCAL_MODULE_FILENAME := libgame
    LOCAL_SRC_FILES := hellocpp/main.cpp \
    ../../Classes/AppDelegate.cpp \
    ../../Classes/HelloWorldScene.cpp
    LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
    LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static cocos_extension_static
    include $(BUILD_SHARED_LIBRARY)
    $(call import-module,CocosDenshion/android) \
    $(call import-module,cocos2dx) \
    $(call import-module,extensions)

    Definitely I have no knowledge to adapt this tutorial .. Any help?

    Reply
  • September 18, 2012 at 6:12 pm
    Permalink

    Great Article, any chance of an update for the last part, it seems things have been changed in 2.0.2 :(

    Reply
  • November 1, 2012 at 2:34 am
    Permalink

    great tutorial, but I got a little problem when I try to $COCOS2DX_ROOT/SimpleGame/android/build_native.sh
    I get to “Using prebuilt externals” but then and error
    ine 90: /opt/Android/android-ndk-r7b/ndk-build: No such file or directory
    I check the folder and ndk-build is there. Could you help me?

    Reply
    • November 1, 2012 at 4:41 am
      Permalink

      I manage to get the ndk-build working but when I use $COCOS2DX_ROOT/create-android-project.sh I only get 3 folders Class, proj.android, Resources.
      When I try build_native.sh I get
      Android NDK: Your APP_BUILD_SCRIPT points to an unknown file: ./jni/Android.mk
      Am I making a wrong step here?

      Reply
  • April 3, 2013 at 10:37 pm
    Permalink

    I have compiled and everything works fine till compilation. When I try to run it under Eclipse and run it on my android the application crashes on start.

    Following is the stacktrace. Can you help ?

    04-03 21:32:31.420: E/AndroidRuntime(12714): FATAL EXCEPTION: main
    04-03 21:32:31.420: E/AndroidRuntime(12714): java.lang.ExceptionInInitializerError
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.Class.newInstanceImpl(Native Method)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.Class.newInstance(Class.java:1409)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1761)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.ActivityThread.access$1500(ActivityThread.java:124)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:947)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.os.Handler.dispatchMessage(Handler.java:99)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.os.Looper.loop(Looper.java:130)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at android.app.ActivityThread.main(ActivityThread.java:3822)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.reflect.Method.invokeNative(Native Method)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.reflect.Method.invoke(Method.java:507)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at dalvik.system.NativeStart.main(Native Method)
    04-03 21:32:31.420: E/AndroidRuntime(12714): Caused by: java.lang.UnsatisfiedLinkError: Cannot load library: link_image[1964]: 90 could not load needed library ‘libbox2d.so’ for ‘libgame.so’ (load_library[1106]: Library ‘libbox2d.so’ not found)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.Runtime.loadLibrary(Runtime.java:434)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at java.lang.System.loadLibrary(System.java:554)
    04-03 21:32:31.420: E/AndroidRuntime(12714): at org.news.test.me.newTestMe.(newTestMe.java:62)
    04-03 21:32:31.420: E/AndroidRuntime(12714): … 15 more

    I have 7 files in my libs->armeabi folder … gdb.setup, gdbserver,libbox2d.so,libcocos2d.so, libcocosdenshion.so, libgame_logic.so and lib_game.so

    Reply
    • April 3, 2013 at 10:39 pm
      Permalink

      Yah I figured it out …

      static {
      System.loadLibrary(“box2d”);
      System.loadLibrary(“cocos2d”);
      System.loadLibrary(“cocosdenshion”);
      System.loadLibrary(“game_logic”);
      System.loadLibrary(“game”);

      }

      I was putting box2d in the last line, because of which game_logic was not working … Thanks .. nice tutorial :)

      Reply
  • March 11, 2014 at 8:52 am
    Permalink

    hi.,
    I got this tye of erroe and not go further..can u solve this i am new in cocos2dx .

    Input package path. For example: org.cocos2dx.example
    org.cocos2dx.simplegame
    Now cocos2d-x supports Android 2.2 or upper version
    ./create-android-project.sh: line 107: /home/laschweinski/android/android-sdk-linux_86/tools/android: No such file or directory
    input target id:

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" cssfile="">

Email
Print