使用c++在iphone和android开发程序

以下文字摘自:

http://gameit.ro/2011/08/creating-an-iphone-and-android-cocos2d-x-hybrid-project/

懒得翻译了就直接贴出来了。

This post has been updated with the latest version of Cocos2D-x here:

Creating an iPhone and Android Cocos2D-x hybrid project (updated)
. Unless you have a very specific reason to use an older version of the library, please use the updated article.

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.

Before we begin

It is probably a better and considerably less painful option to just take the example HelloWorld project from the Cocos2D-x zip file and use that as a starting point for your project.

With a bit of care and finesse you should be able to rename the project files to match your game’s name.

Personally, I wanted to get a feel of the internal build process of a Cocos2D-x project, that’s why I decided I would hustle to see this through.

Prerequisites

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 c2dx 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

I actively despise and hate XCode4 for a various number of reasons, and one of them is that when you create a new project it will place the project file in a folder above the one that contains the classes folder, that’s why I always keep around a copy of
XCode3 (they appear to be happily cohabiting together).

Cocos2D-x provides a bunch of templates for both XCode3 and 4 that will create the project along with all that is needed. The templates for XCode3 are better suited for our goal, in the sense that they copy over the Cocos2D-X files for all the platforms
supported by it, as opposed to the Xcode4 templates that will only copy the bare minimum.

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 3 for the XCode 3 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 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 cocos2dx folder.

A difference between the XCode3 and 4 templates is that XCode3 will store its resources in a folder called
Resource (note the lack of the trailing s), while Xcode4 will use the standard
Resources folder. This seems to be a typo in their system, but the good news is that the Android wizard uses the Resource folder as well. This will change in a future release as this
“bug” appears to be fixed.

Creating the Android project

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

./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, type 5 and hit enter. 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.

For some reason, the Android wizard will not set the appropriate executable flag on the
build_native.sh file so we are going to do that manually. build_native.sh is the file that is used to compile the game for Android using the NDK. If you did not set the appropriate paths in your .bash_profile, build_native is going
to crash on you because it won’t be able to find the ndk-build executable from the NDK.

To make build_native.sh executable type the following in the terminal:
chmod u+x $COCOS2DX_ROOT/SimpleGame/android/build_native.sh

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.

That being said, 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.

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.

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/Resource

I deleted the ANDROID_NDK_ROOT definition because that variable is already set by the
.bash_profile file.

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)/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 
../../../Classes/AppDelegate.cpp 
../../../Classes/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)/../../../Classes
# it is used for ndk-r4
# if you build with nkd-r4, uncomment it
# LOCAL_LDLIBS := -L$(LOCAL_PATH)/../../libs/armeabi -lcocos2d -llog -lcocosdenshion 
#                -L$(LOCAL_PATH)/../../libs/cocos2dx/platform/third_party/android/libraries -lcurl

# it is used for ndk-r5
# if you build with ndk-r4, comment it
# because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/)
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) 
                -lcocos2d -llog -lcocosdenshion 
                -L$(call host-path, $(LOCAL_PATH)/../../../libs/cocos2dx/platform/third_party/android/libraries) -lcurl

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, we go to the root of our project and then enter the
libs folder.

The Xcode3 template has an issue that causes it to create the AppDelegate file (the entry file to your application) with the wrong filename, so instead of creating the files AppDelegate.h and AppDelegate.cpp,
it will create SimpleGameAppDelegate.h and SimpleGameAppDelegate.cpp.

You will need to rename these two files in XCode to AppDelegate.h and .cpp, and change any old references to the SimpleGameAppDelegate.h file to the new file.

Since all seems to be done, 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.

Now you should be able to call build_native.sh from the android folder 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.

Conclusions

What is blatantly obvious from this entire article is that Cocos2D-x is seriously lacking in polishing with respect to developer tools.

You shouldn’t have to jump through that many hoops to be able to create a hybrid iPhone/Android multiplatform project. I haven’t even given thought to how to integrate this with the Win32 platform or anything similar, but I am guessing that’s another round
of pain.

My bash-fu is seriously lacking, but it would be absolutely awesome and also a killer feature if one could create a script that would generate the necessary project architecture for the given architectures, something like:

~ ./create_project.sh
Available platforms:
  ios - iOS (iPhone OS)
  android - Google Android
  win32 - Microsoft Windows
  wophone - WoPhone
Please type the platforms that you want to support (e.g. ios android):
> ios android win32

Project name (e.g. TestGame):
> MyGame

Project identifier (e.g. org.cocos2dx.testgame):
> org.cocos2dx.mygame

=======================
Available add-ons:
  chipmunk - Chipmunk physics engine
  box2d - Box2D physics engine
  lua - Support for the Lua scripting language
  none - None of the above

Please type the add-ons that you want to add:
> none

=======================
== iOS ================
=======================
Do you want support for iPad? (yes/no)
> no

=======================
== Android ============
=======================
[... Android specific questions ...]

I’ll take a look what can be done with XCode’s CLI, maybe there is support for creating a new project from the command line.

Tagged with:  

41 Responses to Creating an iPhone and Android Cocos2d-x hybrid project

  1. […] it and  to actually start creating something cross-platform and useful? You can find out following this link which will walk you a bit world of cocos2d-x and iPhone / Android cross-platform […]

  2. Thanks for the great tutorial it really helped me a lot :)

  3. […] those of you who have followed my Creating an iPhone and Android Cocos2d-x hybrid project tutorial please pay attention to the paths. When you see a path that references the libraries […]


  4. Mayank Saini
    says:

    Hey i was following your tutorial.. and i have everything configured and working fine.. except for the last step. When i run the build_native.sh file it gives this error : cannot find -lcocos2d

    Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
    Gdbsetup : libs/armeabi/gdb.setup
    SharedLibrary : libgame.so
    /Users/mayanksaini/Documents/android-ndk-r5/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: *** [/Users/mayanksaini/documents/hybridApp/android/obj/local/armeabi/libgame.so] Error 1


  5. gyen hiyuu says:

    Thank you for your tutorial.
    I was following your tutorial to the ending. But at last, when i executed build_native.sh, there are some errors.

    I found that there are not Android.mk file, android/Android.mk in the cocos2dx and CocosDenshion of libs folder.
    Here is the error message:

    /Users/myusername/working/SimpleGame/SimpleGame/android/jni/Android.mk:10: /Users/myusername/working/SimpleGame/SimpleGame/android/jni/../../libs/cocos2dx/Android.mk: No such file or directory
    /Users/myusername/working/SimpleGame/SimpleGame/android/jni/Android.mk:10: /Users/myusername/working/SimpleGame/SimpleGame/android/jni/../../libs/CocosDenshion/android/Android.mk: No such file or directory
    make: *** No rule to make target `/Users/myusername/working/SimpleGame/SimpleGame/android/jni/../../libs/CocosDenshion/android/Android.mk’. Stop.

    I’m using XCode 4 and cocos2d-x version cocos2d-1.0.1-x-0.9.1
    Did i do something wrong. Please help me.


    • clw says:

      Do you have the libs folder under /Users/myusername/working/SimpleGame/SimpleGame/ ?


      • gyen hiyuu says:

        Yes, I have. There are 2 folders cocos2dx and CocosDenshion in libs folder.


        • clw says:

          It just clicked in my mind that you said that you are using XCode 4. The problem is that the XCode 4 template (as opposed to theXCode 3 template) does not copy over the Android specific files.

          One quick way to solve this would be to copy over the cocos2dx and CocosDenshion from your cocos2dx installation (from the cocos2d-1.0.1-x-0.9.1 folder). These should overwrite the two folders in your libs directory.

          Make sure you make a backup of your project before performing this.


  6. William says:

    I’ve gotten this all set up, but when I try to build I get a bundle or errors. If in Xcode I create new cpp and h files under the class folder, they actually got into the base folder…inside xcode, I can just include them from the AppDelegate with #include
    “GameManager.h” and it works. However, using the ./build_native.sh command I get that files are missing.

    Compile++ thumb : game <= AppDelegate.cpp
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp:12:25: error: GameManager.h: No such file or directory
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp: In member function ‘virtual bool AppDelegate::applicationDidFinishLaunching()’:
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp:99: error: ‘GameManager’ has not been declared
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp:99: error: ‘kMainMenuScene’ was not declared in this scope
    make: *** [/xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/obj/local/armeabi/objs-debug/game/../../../Classes/AppDelegate.o] Error 1

    Additionally, if I include the file as “../GameManager” it seems to find the files, but then gives me this error set…

    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/obj/local/armeabi/objs-debug/game/../../../Classes/AppDelegate.o: In function `AppDelegate::applicationDidFinishLaunching()’:
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp:99: undefined reference to `GameManager::sharedGameManager()’
    /xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/jni/helloworld/../../../Classes/AppDelegate.cpp:99: undefined reference to `GameManager::runSceneWithID(SceneType)’
    collect2: ld returned 1 exit status
    make: *** [/xcodeapps/cocos2dxtestapp/cocos2dxtestapp/android/obj/local/armeabi/libgame.so] Error 1

    Again, it all works just fine on the iPhone…any ideas? I have a feeling it would be adding another include path to the makefil instructions or something but I’m absolutely terrible at figuring that sort of thing out.


    • William says:

      Sorry to spam with those errors, here was my solution that I probably should have just known anyways….

      In the helloworld folder’s Android.mk I made these changes…

      LOCAL_SRC_FILES := main.cpp
      ../../../Classes/AppDelegate.cpp
      ../../../Classes/HelloWorldScene.cpp
      ../../../GameManager.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)/../../..
      $(LOCAL_PATH)/../../../Classes

      I have the root directory available for includes now I guess, and I must compile all cpp files in the space up above
      :) So used to working in an IDE without having to worry about makefiles that I guess I went dumb


  7. ioodo says:

    thank you very much, it is great work.


  8. vishesh says:

    ok i am curious,

    when we’re done creating the droid project,what happens if

    instead of moving the android folder into the iphone project folder,we move the contents of the iphone project into the android folder?
    do we still need to edit paths in the xcode project ?
    i’ve copied the iphone project to another location and it seems to open fine…chances are im wrong in doing this,but i hope that this works…so what if ure project has to reside inside the cocos2d-x folder ?
    can u give this a shot and post the result ?


  9. vishesh says:

    ok so i did copy the xcode project’s contents into the android project directory, and opened the xcode project and hit build, it runs fine on iphone simulator,
    im not sure if it runs fine on droid, checking now


  10. vishesh says:

    so is it working both on iphone and droid ?

    i caught viral fever and im unable to test it out…cant sit too long on hte machine,
    will try it out whn i get well…

    so then if it does work on both, its probably the best approach isnt it?
    how do i dl the whole folder from github ?
    and anyway,why bother to find out why,it works…just copy the lib folder,
    can u zip it up(the lib folder) and post a dl link here so every1 can get it working…


  11. vishesh says:

    i dl’d the project replaced the libs, but im unable to run it from eclipse

    strange issues are popping up mostly about permissions

    /adsda/asddvw is read-only etc…so i just made the whole folder shared…now its opening the project,but says” /gen folder already exists but is not source folder”.
    so i deleted it, made a new source folder /gen and from android tools did “fix project properties”

    now it wont run… “your project has errors” but its not showing any errors in any logs,nothing in console

    i think this project is f’d…will try again with a new project…if u get it working please share how


    • clw says:

      Hi Visesh

      The instructions above are working, you just need to pay careful attention to them. Plenty of people are using them.

      I think you will have a better chance of getting this to work if start a new project and follow the instructions exactly as they are provided. Normally you wouldn’t need to manually recreate the gen folder or run “fix project properties”. Also, you shouldn’t
      need to mess with the permissions as the default setup should work out of the box.

      I am not sure what you are trying to accomplish there, but you may be better off staying on the beaten path and setting up the project as most of us do. You’re spending a lot more time getting to your desired project structure, rather than working on your
      game.

      Good luck :)


  12. Black says:

    Hi,

    I’ve been following along, however when I do the last step (run the build_native.sh), the last line of the compilation returns with this error. I did some of the things mentioned (copied the cocos2dx folders from the installation folder). I checked, but
    I don’t have two Android.mk files in the same directory. I am using Android 2.1, NDK 7 & the latest version of Cocos2dx, any assistance you could provide would be appreciated.

    Compile++ thumb : game <= main.cpp
    Compile++ thumb : game <= AppDelegate.cpp
    Compile++ thumb : game <= HelloWorldScene.cpp
    SharedLibrary : libgame.so
    /Users/Black/Projects/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.so] Error 1
    :android Black$


    • clw says:

      Looks like you do not have libcurl installed:
      /Users/Black/Projects/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

      Make sure you have libcurl on your system.


      • Black says:

        Hi,

        when I navigate to my game’s root directory and then libs/cocos2dx/platform/third_party/android/libraries/, there are 3 directories armeabi, armeabi-v7a and x86. They all have a file called libcurl.a, is this the file I should have or do I have to install
        libcurl on my machine?

        also in my Android.mk file (in the jni/helloworld) I have this set, shouldn’t this include anything under this directory?
        $(LOCAL_PATH)/../../../libs/cocos2dx/platform

        thanks for your assistance.


        • Black says:

          ok so after messing around some more it seems like if I build the project up until the point of merger it works fine. I am able to load the android project and run on the simulator, however when I try and merge the project is where I’m having issues. For
          some reason it just doesn’t work. I’ve been at this for 4 days trying to get this to work.

          do I have to merge the projects? If I don’t, will I have to maintain two code bases or keep copying files back & forth?

          thanks,


          • David says:

            Hi,

            I had the same problem and it was due to a difference in the libraries between the current release of cocos2dx and whatever version the author of the tutorial used.

            If you look at the SimpleGame/android/jni/helloworld/Android.mk file:

            here’s the offending line:

            -L$(call host-path, $(LOCAL_PATH)/../../../libs/cocos2dx/platform/third_party/android/libraries) -lcurl

            make it:

            -L$(call host-path, $(LOCAL_PATH)/../../../libs/cocos2dx/platform/third_party/android/libraries/armeabi-v7a) -lcurl

            or maybe just armeabi withouth the -v7a but the above works for me. I think you might need the plain version for older phones but I’m out of my element here.

            HTH,
            David


          • krystian says:

            Hey Black,

            I’m having the same problem. Android.mk files have changed since this tutorial was created. I’m trying to figure this out as well. When I get something I will post back.


  13. Eugene says:

    And how are you resolved this problem?


  14. krystian says:

    Ok… so a little update for cocos2d-1.0.1-x-0.10.0
    1. You will have to copy Android.mk from Classes directory in your android generated project to Classes directory in your ios project

    2. Classes/Android.mk file should look like:

    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)

    your android/jni/Android.mk file should look like this:

    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)

    and finally your android/jni/helloworld/Android.mk file should look like:


    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)

    Phew… hope this helps, as it did the trick for me :)


  15. Esteban Padilla says:

    Hi, first of all i would like to thank you for this tutorial. I know that is quit a while since your wrote it but i am having this error when calling the build_native.sh.

    esteban-mini:android epadilla$ ./build_native.sh
    jni/Android.mk:10: jni/../../libs/cocos2dx/Android.mk: No such file or directory
    jni/Android.mk:10: jni/../../libs/CocosDenshion/android/Android.mk: No such file or directory
    jni/Android.mk:10: jni/helloworld/Android.mkLOCAL_PATH: No such file or directory
    jni/Android.mk:10: :=: No such file or directory
    make: *** /Users/esteban/Development/Android/AndroidNDK/build/core: Is a directory. Stop.

    I would really appreciate if you can point me to the right direction on this problem,
    Thank you very much.
    EPadilla


  16. Esteban Padilla says:

    Thank you so much for the information, i was able to run the and it did no give any errors, but when i created the android project on Eclipse and try to run it gave me a few error, mostly regarding override methods, i clean the code and run the project on
    eclipse again and I was able to install the app on the virtual device but not to run it, it seems the app crashes on the virtual device. I was wondering if that ever happened to you?
    Thank you again.

    EPadilla


    • Esteban Padilla says:

      I just see this article
      http://gameit.ro/2011/08/creating-a-cocos2d-x-box2d-android-project/
      I am going to follow it and see what happens thx again.

      EPadilla


    • Esteban Padilla says:

      Well, it seems that all went ok creating the android project and xcode project.
      I was able to run and compile the app on Eclipse after getting some errors on files like SimpleGame.java and the AndroidManifest.xml also all the override tags i deleted from the files Cocos2dxGLSurfaceView.java and Cocos2dxAccelerometer.java.

      I clean the project and run, i get on console:

      [2012-02-21 20:26:11 – SimpleGame] Android Launch!
      [2012-02-21 20:26:11 – SimpleGame] adb is running normally.
      [2012-02-21 20:26:11 – SimpleGame] Performing org.cocos2dx.simplegame.SimpleGame activity launch
      [2012-02-21 20:26:11 – SimpleGame] Automatic Target Mode: launching new emulator with compatible AVD ‘myAVD’
      [2012-02-21 20:26:11 – SimpleGame] Launching a new emulator with Virtual Device ‘myAVD’
      [2012-02-21 20:26:15 – Emulator] 2012-02-21 20:26:15.031 emulator-arm[2552:1107] Warning once: This application, or a library it uses, is using NSQuickDrawView, which has been deprecated. Apps should cease use of QuickDraw and move to Quartz.
      [2012-02-21 20:26:15 – Emulator] emulator: WARNING: Unable to create sensors port: Connection refused
      [2012-02-21 20:26:15 – SimpleGame] New emulator found: emulator-5554
      [2012-02-21 20:26:15 – SimpleGame] Waiting for HOME (‘android.process.acore’) to be launched…
      [2012-02-21 20:26:43 – SimpleGame] HOME is up on device ‘emulator-5554′
      [2012-02-21 20:26:43 – SimpleGame] Uploading SimpleGame.apk onto device ‘emulator-5554′
      [2012-02-21 20:26:44 – SimpleGame] Installing SimpleGame.apk…
      [2012-02-21 20:27:09 – SimpleGame] Success!
      [2012-02-21 20:27:09 – SimpleGame] Starting activity org.cocos2dx.simplegame.SimpleGame on device emulator-5554
      [2012-02-21 20:27:10 – SimpleGame] ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=org.cocos2dx.simplegame/.SimpleGame }

      The AVD opens and it gives me the error:
      Unfortunately, SimpleGame has stopped.

      It seems the app is install on AVD but when I launched i get the same error.

      Do you have any suggestions?
      I would really appreciate if you do.

      Thank you again.
      EPadilla


  17. Marco says:

    I had some problems with the Android section: it was missing some references in build_native.sh, here the solution
    http://www.cocos2d-x.org/boards/10/topics/6766, hope it helps
    :)

  18. I ported cocos2d-x’s “chipmunk” & “BOX2D” to the Android Apps as to work.
    Prease also see this site of “github” below.
    https://github.com/hirokazuono/Chipmunk_and_BOX2D_of_cocos2dx_ported_to_Android
    ( Incidentally,description in this github is that I had organized collectively on my own.)

    kanrinin_kanmasato(hirokazu_ono minatoku minatoku kaigan1 tokyo japan)

    Movie -> http://youtu.be/fEVbocT8BtE
    or ->
    http://www.firstpost.com/topic/product/android-cocos2dx-cocos2d-xbox2dchipmunk-to-video-fEVbocT8BtE-53093-1.html

    ————–
    (Sorry, the urls below are in case of the posted urls above that can’t cliclable.)

    site

    movie

    anothe place that posted the movie.

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

One Reply to “使用c++在iphone和android开发程序”

留言

你的邮箱是保密的 必填的信息用*表示