cocos2d-x(2.0.2)的win32工程移植到Android

前端之家收集整理的这篇文章主要介绍了cocos2d-x(2.0.2)的win32工程移植到Android前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

STEP 1:配置android工程生成

用edit plus之类编辑器打开cocos2d-x目录下的create-android-project.bat,并进行修改


注意:上述文件中的几个路径一定要与你自己的路径对应起来!
STEP 2:创建android工程

这一步是通过运行cocos2d-x目录下的create-android-project.bat实现的(在WINDOWS资源管理器中右键单击此文件,然后选择以管理员身份运行即可)。参考其它的资料,我使用管理员身份运行此文件的(一般运行情况还没有试验)。

然后,屏幕上提示你输入包名和项目名。
注意:如果在2.0.2版本中,如果你输入一个已经存在的项目名,则系统会提示你,已经存在同名,不允许你创建并退出。另外一定要小记注意,这一步是运行文件 create-android-project.bat而不是另一个相同主文件名的create-android-project.sh!!!—–这个文件后面才使用; 否则整个步骤乱套了!!!


我的例子中创建的WIN32项目为eee2,这里创建的ANDROID工程名称为eee21。之后,系统自动运行,并创建项目,其下有三个子文件夹:Classes,proj.android和Resources。


STEP 3:导入代码和有关资源

现在,
把你win32项目里的Classes拷贝到当前Classes下。然后把你win32项目里的Resources拷贝到当前Resources下。
提示:2.0.2版本与1.x版本中管理资源的方式发生了较大变化,请注意这一点。当然,在高版本中,管理更为方便和科学了。
提示2:直接使用覆盖方式复制粘贴即可另外还要想着把最初系统自动生成的几个可能不再有用的文件删除

STEP 4:编辑jni文件夹下的android.mk等文件

这一步比较复杂,要求你最好深入理解application.mk和android.mk这两个文件在NDK编程中的位置及详细作用。在此不具体展开介绍了。

因为,我的例子是一个由系统向导自动生成的HELLO WORLD级的程序,所以,一路走下来非常顺利。
我的android.mk文件修改为如下形式:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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_PATH)/../../../cocos2dx \
$(LOCAL_PATH)/../../../cocos2dx/platform. \
$(LOCAL_PATH)/../../../cocos2dx/include \
$(LOCAL_PATH)/../../../cocosDension/include
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)

我的更改有:
1,注释掉了LOCAL_MODULE_FILENAME := libgame这一句。
2,把共享库名字更改为game_shared,对应于eee21.java文件中的下面一句必须作相应的修改

?
1
System.loadLibrary( "game_shared" );

3,根据我的ANDROID工程所在位置修改了头文件引用部分。

?
1
2
3
4
5
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \
$(LOCAL_PATH)/../../../cocos2dx \
$(LOCAL_PATH)/../../../cocos2dx/platform. \
$(LOCAL_PATH)/../../../cocos2dx/include \
$(LOCAL_PATH)/../../../cocosDension/include

其中, $(LOCAL_PATH)是jni文件夹,于是相对于这一级文件夹,你的cocos2d-x系统的相应的头文件在哪一级文件夹下要明明白白才行。

STEP 4:运行build_native.sh脚本文件编译生成so库

根据网络的参考资料,我以系统管理员身份运行cycwin。然后运行你的系统生成的ANDROID工程内proj.android文件夹下的build_native.sh脚本文件,我的文件位置在:
E:\download2010\cocos2d-x\cocos2d-2.0-x-2.0.2\eee21\proj.android
一般是先切换到上述文件夹下,然后再运行那个脚本文件,我的命令是:
1. cd /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android

2../build_native.sh
输出结果是:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
@H_870_502@ 69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
@H_403_800@ 218
219
220
221
222
223
NDK_ROOT = /cygdrive/d/ndkr8
COCOS2DX_ROOT = /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/pro
j.android/../..
APP_ROOT = /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.and
roid/..
APP_ANDROID_ROOT = /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/
proj.android
Using prebuilt externals
make: Entering directory `/cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2
/eee21/proj.android'
Gdbserver : [arm-linux-androideabi-4.4.3] libs/armeabi/gdbserver
Gdbsetup : libs/armeabi/gdb.setup
Cygwin : Generating dependency file converter script
Compile++ thumb : game_shared <= main.cpp
Compile++ thumb : game_shared <= AppDelegate.cpp
Compile++ thumb : game_shared <= HelloWorldScene.cpp
Prebuilt : libgnustl_static.a <= <NDK>/sources/cxx-stl/gnu-libstdc++/libs/
armeabi/
Compile++ thumb : cocos2dx_static <= CCConfiguration.cpp
Compile++ thumb : cocos2dx_static <= CCDrawingPrimitives.cpp
Compile++ thumb : cocos2dx_static <= CCScheduler.cpp
Compile++ thumb : cocos2dx_static <= CCCamera.cpp
Compile++ thumb : cocos2dx_static <= CCAction.cpp
Compile++ thumb : cocos2dx_static <= CCActionCamera.cpp
Compile++ thumb : cocos2dx_static <= CCActionCatmullRom.cpp
Compile++ thumb : cocos2dx_static <= CCActionEase.cpp
Compile++ thumb : cocos2dx_static <= CCActionGrid.cpp
Compile++ thumb : cocos2dx_static <= CCActionGrid3D.cpp
Compile++ thumb : cocos2dx_static <= CCActionInstant.cpp
Compile++ thumb : cocos2dx_static <= CCActionInterval.cpp
Compile++ thumb : cocos2dx_static <= CCActionManager.cpp
Compile++ thumb : cocos2dx_static <= CCActionPageTurn3D.cpp
Compile++ thumb : cocos2dx_static <= CCActionProgressTimer.cpp
Compile++ thumb : cocos2dx_static <= CCActionTiledGrid.cpp
Compile++ thumb : cocos2dx_static <= CCActionTween.cpp
Compile++ thumb : cocos2dx_static <= CCAtlasNode.cpp
Compile++ thumb : cocos2dx_static <= CCNode.cpp
Compile++ thumb : cocos2dx_static <= CCAffineTransform.cpp
Compile++ thumb : cocos2dx_static <= CCGeometry.cpp
Compile++ thumb : cocos2dx_static <= CCAutoreleasePool.cpp
Compile++ thumb : cocos2dx_static <= CCDictionary.cpp
Compile++ thumb : cocos2dx_static <= CCNS.cpp
Compile++ thumb : cocos2dx_static <= CCObject.cpp
Compile++ thumb : cocos2dx_static <= CCSet.cpp
Compile++ thumb : cocos2dx_static <= CCString.cpp
Compile++ thumb : cocos2dx_static <= CCZone.cpp
Compile++ thumb : cocos2dx_static <= CCArray.cpp
Compile++ thumb : cocos2dx_static <= cocos2d.cpp
Compile++ thumb : cocos2dx_static <= CCDirector.cpp
Compile++ thumb : cocos2dx_static <= CCGrabber.cpp
Compile++ thumb : cocos2dx_static <= CCGrid.cpp
Compile thumb : cocos2dx_static <= aabb.c
Compile thumb : cocos2dx_static <= mat3.c
Compile thumb : cocos2dx_static <= mat4.c
Compile thumb : cocos2dx_static <= neon_matrix_impl.c
Compile thumb : cocos2dx_static <= plane.c
Compile thumb : cocos2dx_static <= quaternion.c
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../cocos2dx/
kazmath/src/quaternion.c: In function 'kmQuaternionAssign' :
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../cocos2dx/
kazmath/src/quaternion.c:478: warning: incompatible implicit declaration of buil
t-in function 'memcpy'
Compile thumb : cocos2dx_static <= ray2.c
Compile thumb : cocos2dx_static <= utility.c
Compile thumb : cocos2dx_static <= vec2.c
Compile thumb : cocos2dx_static <= vec3.c
Compile thumb : cocos2dx_static <= vec4.c
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../cocos2dx/
@H_870_502@ kazmath/src/vec4.c: In function 'kmVec4Assign' :
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../cocos2dx/
kazmath/src/vec4.c:150: warning: incompatible implicit declaration of built-in f
unction 'memcpy'
Compile thumb : cocos2dx_static <= mat4stack.c
Compile thumb : cocos2dx_static <= matrix.c
Compile++ thumb : cocos2dx_static <= CCKeypadDelegate.cpp
Compile++ thumb : cocos2dx_static <= CCKeypadDispatcher.cpp
Compile++ thumb : cocos2dx_static <= CCLabelAtlas.cpp
Compile++ thumb : cocos2dx_static <= CCLabelBMFont.cpp
Compile++ thumb : cocos2dx_static <= CCLabelTTF.cpp
Compile++ thumb : cocos2dx_static <= CCLayer.cpp
Compile++ thumb : cocos2dx_static <= CCScene.cpp
Compile++ thumb : cocos2dx_static <= CCTransitionPageTurn.cpp
Compile++ thumb : cocos2dx_static <= CCTransition.cpp
Compile++ thumb : cocos2dx_static <= CCTransitionProgress.cpp
Compile++ thumb : cocos2dx_static <= CCMenu.cpp
Compile++ thumb : cocos2dx_static <= CCMenuItem.cpp
Compile++ thumb : cocos2dx_static <= CCMotionStreak.cpp
Compile++ thumb : cocos2dx_static <= CCProgressTimer.cpp
Compile++ thumb : cocos2dx_static <= CCRenderTexture.cpp
Compile++ thumb : cocos2dx_static <= CCParticleExamples.cpp
Compile++ thumb : cocos2dx_static <= CCParticleSystem.cpp
Compile++ thumb : cocos2dx_static <= CCParticleBatchNode.cpp
Compile++ thumb : cocos2dx_static <= CCParticleSystemQuad.cpp
Compile++ thumb : cocos2dx_static <= CCSAXParser.cpp
Compile++ thumb : cocos2dx_static <= CCThread.cpp
Compile++ thumb : cocos2dx_static <= platform.cpp
Compile++ thumb : cocos2dx_static <= CCEGLViewProtocol.cpp
Compile++ thumb : cocos2dx_static <= CCEGLView.cpp
Compile++ thumb : cocos2dx_static <= CCAccelerometer.cpp
Compile++ thumb : cocos2dx_static <= CCApplication.cpp
Compile++ thumb : cocos2dx_static <= CCCommon.cpp
Compile++ thumb : cocos2dx_static <= CCFileUtils.cpp
Compile++ thumb : cocos2dx_static <= CCImage.cpp
Compile++ thumb : cocos2dx_static <= EditBoxJni.cpp
Compile++ thumb : cocos2dx_static <= JniHelper.cpp
Compile++ thumb : cocos2dx_static <= IMEJni.cpp
Compile++ thumb : cocos2dx_static <= MessageJni.cpp
Compile++ thumb : cocos2dx_static <= SensorJni.cpp
Compile++ thumb : cocos2dx_static <= SystemInfoJni.cpp
Compile++ thumb : cocos2dx_static <= TouchesJni.cpp
Compile++ thumb : cocos2dx_static <= CCScriptSupport.cpp
Compile++ thumb : cocos2dx_static <= ccShaders.cpp
Compile++ thumb : cocos2dx_static <= CCGLProgram.cpp
Compile++ thumb : cocos2dx_static <= ccGLStateCache.cpp
Compile++ thumb : cocos2dx_static <= CCShaderCache.cpp
Compile++ thumb : cocos2dx_static <= CCAnimation.cpp
Compile++ thumb : cocos2dx_static <= CCAnimationCache.cpp
Compile++ thumb : cocos2dx_static <= CCSprite.cpp
Compile++ thumb : cocos2dx_static <= CCSpriteBatchNode.cpp
Compile++ thumb : cocos2dx_static <= CCSpriteFrame.cpp
Compile++ thumb : cocos2dx_static <= CCSpriteFrameCache.cpp
Compile++ thumb : cocos2dx_static <= CCNotificationCenter.cpp
Compile++ thumb : cocos2dx_static <= CCProfiling.cpp
Compile++ thumb : cocos2dx_static <= CCPointExtension.cpp
Compile++ thumb : cocos2dx_static <= TransformUtils.cpp
Compile++ thumb : cocos2dx_static <= CCUserDefault.cpp
Compile++ thumb : cocos2dx_static <= base64.cpp
Compile++ thumb : cocos2dx_static <= ccUtils.cpp
Compile++ thumb : cocos2dx_static <= CCVertex.cpp
Compile++ thumb : cocos2dx_static <= ccCArray.cpp
Compile++ thumb : cocos2dx_static <= TGAlib.cpp
Compile++ thumb : cocos2dx_static <= ZipUtils.cpp
Compile++ thumb : cocos2dx_static <= ioapi.cpp
Compile++ thumb : cocos2dx_static <= unzip.cpp
Compile++ thumb : cocos2dx_static <= CCIMEDispatcher.cpp
Compile++ thumb : cocos2dx_static <= CCTextFieldTTF.cpp
Compile++ thumb : cocos2dx_static <= CCTexture2D.cpp
Compile++ thumb : cocos2dx_static <= CCTextureAtlas.cpp
Compile++ thumb : cocos2dx_static <= CCTextureCache.cpp
Compile++ thumb : cocos2dx_static <= CCTexturePVR.cpp
Compile++ thumb : cocos2dx_static <= CCParallaxNode.cpp
Compile++ thumb : cocos2dx_static <= CCTMXLayer.cpp
Compile++ thumb : cocos2dx_static <= CCTMXObjectGroup.cpp
Compile++ thumb : cocos2dx_static <= CCTMXTiledMap.cpp
Compile++ thumb : cocos2dx_static <= CCTMXXMLParser.cpp
Compile++ thumb : cocos2dx_static <= CCTileMapAtlas.cpp
Compile++ thumb : cocos2dx_static <= CCTouchDispatcher.cpp
Compile++ thumb : cocos2dx_static <= CCTouchHandler.cpp
Compile++ thumb : cocos2dx_static <= CCTouch.cpp
Prebuilt : png.a <= /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2
/eee21/proj.android/../../cocos2dx/platform/third_party/android/prebuilt/libpng/
libs/armeabi/
Prebuilt : jpeg.a <= /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.
2/eee21/proj.android/../../cocos2dx/platform/third_party/android/prebuilt/libjpe
g/libs/armeabi/
Prebuilt : xml2.a <= /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.
2/eee21/proj.android/../../cocos2dx/platform/third_party/android/prebuilt/libxml
2/libs/armeabi/
Prebuilt : tiff.a <= /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.
2/eee21/proj.android/../../cocos2dx/platform/third_party/android/prebuilt/libtif
f/libs/armeabi/
StaticLibrary : libcocos2d.a
Compile++ thumb : cocosdenshion_static <= SimpleAudioEngine.cpp
Compile++ thumb : cocosdenshion_static <= SimpleAudioEngineJni.cpp
Compile++ thumb : cocosdenshion_static <= OpenSLEngine.cpp
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../CocosDens
hion/android/opensl/OpenSLEngine.cpp: In function ' bool initAudioPlayer(AudioPla
yer*, const char *)':
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../CocosDens
hion/android/opensl/OpenSLEngine.cpp:292: warning: extended initializer lists on
ly available with -std=c++0x or -std=gnu++0x
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../CocosDens
hion/android/opensl/OpenSLEngine.cpp:292: warning: extended initializer lists on
ly available with -std=c++0x or -std=gnu++0x
Compile++ thumb : cocosdenshion_static <= SimpleAudioEngineOpenSL.cpp
StaticLibrary : libcocosdenshion.a
Compile++ thumb : cocos_extension_static <= CCBFileLoader.cpp
Compile++ thumb : cocos_extension_static <= CCBReader.cpp
E:/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/eee21/proj.android/../../extension
s/CCBReader/CCBReader.cpp:141:52: warning: multi-character character constant
Compile++ thumb : cocos_extension_static <= CCControlButtonLoader.cpp
Compile++ thumb : cocos_extension_static <= CCControlLoader.cpp
Compile++ thumb : cocos_extension_static <= CCLabelBMFontLoader.cpp
Compile++ thumb : cocos_extension_static <= CCLabelTTFLoader.cpp
Compile++ thumb : cocos_extension_static <= CCLayerColorLoader.cpp
Compile++ thumb : cocos_extension_static <= CCLayerGradientLoader.cpp
Compile++ thumb : cocos_extension_static <= CCLayerLoader.cpp
Compile++ thumb : cocos_extension_static <= CCMenuItemImageLoader.cpp
Compile++ thumb : cocos_extension_static <= CCMenuItemLoader.cpp
Compile++ thumb : cocos_extension_static <= CCNodeLoader.cpp
Compile++ thumb : cocos_extension_static <= CCNodeLoaderLibrary.cpp
Compile++ thumb : cocos_extension_static <= CCParticleSystemQuadLoader.cpp
Compile++ thumb : cocos_extension_static <= CCScale9SpriteLoader.cpp
Compile++ thumb : cocos_extension_static <= CCScrollViewLoader.cpp
Compile++ thumb : cocos_extension_static <= CCSpriteLoader.cpp
Compile++ thumb : cocos_extension_static <= CCControl.cpp
Compile++ thumb : cocos_extension_static <= CCControlButton.cpp
Compile++ thumb : cocos_extension_static <= CCControlColourPicker.cpp
Compile++ thumb : cocos_extension_static <= CCControlHuePicker.cpp
Compile++ thumb : cocos_extension_static <= CCControlSaturationBrightnessPicker
.cpp
Compile++ thumb : cocos_extension_static <= CCControlSlider.cpp
Compile++ thumb : cocos_extension_static <= CCControlSwitch.cpp
Compile++ thumb : cocos_extension_static <= CCControlUtils.cpp
Compile++ thumb : cocos_extension_static <= CCInvocation.cpp
Compile++ thumb : cocos_extension_static <= CCMenuPassive.cpp
Compile++ thumb : cocos_extension_static <= CCScale9Sprite.cpp
Compile++ thumb : cocos_extension_static <= CCSpacer.cpp
Compile++ thumb : cocos_extension_static <= CCScrollView.cpp
Compile++ thumb : cocos_extension_static <= CCEditBox.cpp
Compile++ thumb : cocos_extension_static <= CCEditBoxImplAndroid.cpp
Compile++ thumb : cocos_extension_static <= HttpClient.cpp
Prebuilt : curl.a <= /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.
2/eee21/proj.android/../../cocos2dx/platform/third_party/android/prebuilt/libcur
l/libs/armeabi/
StaticLibrary : libextension.a
SharedLibrary : libgame_shared.so
@H_403_800@ Install : libgame_shared.so => libs/armeabi/libgame_shared.so
make: Leaving directory `/cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.2/
eee21/proj.android'
Administrator@Xianzhong-PC /cygdrive/e/download2010/cocos2d-x/cocos2d-2.0-x-2.0.
2/eee21/proj.android

注意:其中有几处警告性提示–这个以后再学习。总之顺利生成了libs文件夹下的.so文件

STEP 5:使用ECLIPSE再编译并打包到真机测试


使用新建android项目下的Create project from existing source:

File -> New -> Project…在随后的”New Project”对话框中选择Android->Android project from existing code,如下所示:

随后出现导入工程对话框,类似(来自于另一个实例)下图所示:

导入成功,然后就是编译执行了。

cocos2d-x作者推荐用上面的.sh方式编译生成.so库文件,然后再用eclipse编译成.apk文件

注意:在导入成功后,我没有作任何修改,先使用Ctrl+B重新编译了一下工程,然后按Ctrl+F11运行。

运行结果:




补充:开发环境

我的开发环境是:
WINDOWS 7
ECLIPSE Indigo Service Release 2
CYGWIN
NDK 8
vs2010
版本的cocos2d-x 2.0.2

相关博文地址:

老G的小屋:http://4137613.blog.51cto.com/4127613/758783

原文链接:https://www.f2er.com/cocos2dx/345658.html

猜你在找的Cocos2d-x相关文章