Cocos2d-x:如何将使用 XCode 开发的 Cocos2d-x 项目移植到 Android(通过 Eclipse)?

Cocos2d-x: How to port a Cocos2d-x project developed with XCode to Android (via Eclipse)?(Cocos2d-x:如何将使用 XCode 开发的 Cocos2d-x 项目移植到 Android(通过 Eclipse)?)

本文介绍了Cocos2d-x:如何将使用 XCode 开发的 Cocos2d-x 项目移植到 Android(通过 Eclipse)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 XCode 开发了一个 Cocos2d-X 应用程序,当我在 iOS 设备上从 XCode 启动它时,它可以完美运行.

I have developed a Cocos2d-X app with XCode which works perfectly when I launch it from XCode on an iOS device.

现在,我想将它移植到 Android.我的理解是,我必须找到一种方法将我的XCode 项目"导入 Eclipse,以便能够编译它并在 Android 设备上启动它.

Now, I want to port it to Android. What I understand is that I have to find a way to import my "XCode project" to Eclipse in order to be able to compile it and launch it on an Android device.

我目前正在尝试按照本教程将此项目转换为混合 iOS/Android 项目:http://gameit.ro/2012/01/creating-an-iphone-and-android-cocos2d-x-hybrid-project-更新/#comment-640

I am currently trying to convert this project to an hybrid iOS/Android project following this tutorial: http://gameit.ro/2012/01/creating-an-iphone-and-android-cocos2d-x-hybrid-project-updated/#comment-640

尽管如此,当我打开这个混合项目时,我没有看到我的任何 cpp 类(cocos2d-x C++ 类)出现在 Eclipse 中,并且在尝试使用 build_native.sh 编译它时出现以下错误:

Nevertheless, I don't see any of my cpp classes (cocos2d-x C++ classes) appearing in Eclipse when I open this hybrid project and I get the following errors when trying to compile it with build_native.sh:

Compile++ thumb  : game_logic <= AppDelegate.cpp
jni/../../Classes/AppDelegate.cpp:14:23: error: IntroMenu.h: No such file or directory
jni/../../Classes/AppDelegate.cpp:15:23: error: GameLayer.h: No such file or directory
jni/../../Classes/AppDelegate.cpp:16:26: error: ScoreManager.h: No such file or directory
jni/../../Classes/AppDelegate.cpp: In member function 'virtual bool AppDelegate::applicationDidFinishLaunching()':
jni/../../Classes/AppDelegate.cpp:99: error: invalid use of incomplete type 'struct ScoreManager'
jni/../../Classes/AppDelegate.h:17: error: forward declaration of 'struct ScoreManager'
jni/../../Classes/AppDelegate.cpp:101: error: invalid use of incomplete type 'struct ScoreManager'
jni/../../Classes/AppDelegate.h:17: error: forward declaration of 'struct ScoreManager'
jni/../../Classes/AppDelegate.cpp:118: error: 'GameLayer' has not been declared
jni/../../Classes/AppDelegate.cpp:120: error: 'IntroMenu' has not been declared
make: *** [obj/local/armeabi/objs-debug/game_logic/AppDelegate.o] Error 1
macbook-de-regis-andre-2:android regisandre$ ./build_native.sh

我必须将一些文件导入 Eclispe 吗?我是否必须修改一些 android.mk 文件?还有什么?

Do I have to import some files to Eclispe? Do I have to modify some android.mk files? Something else?

任何人都可以帮助我或写一个关于这个主题的教程?谢谢!!

Anybody can help me or write a tutorial on this topic? Thanks !!

推荐答案

从外观上看,您需要将自定义创建的文件添加到 LOCAL_SRC_FILES 部分的 Classes/Android.mk 中,如下所示:

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

您需要这样做才能让 android 构建文件知道需要包含在构建过​​程中的新文件.

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.

afaik,您需要为添加到项目中的每个新源文件执行此操作.

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

这篇关于Cocos2d-x:如何将使用 XCode 开发的 Cocos2d-x 项目移植到 Android(通过 Eclipse)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:Cocos2d-x:如何将使用 XCode 开发的 Cocos2d-x 项目移植到 Android(通过 Eclipse)?

基础教程推荐