原文来自:http://space.itpub.net/?uid-14466241-action-viewspace-itemid-744390
STEP 1:配置android工程生成器
我的例子中创建的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文件修改为如下形式:
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文件中的下面一句必须作相应的修改:
System.loadLibrary("game_shared");
3,根据我的ANDROID工程所在位置修改了头文件引用部分。
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
输出结果是:
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/
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
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
详细有这么详细的博文,win32工程移植到win32上没有问题。。。。