瘸腿蛤蟆笔记cocos2d-x-3.2移植到到android步骤及问题定位

cocos2d-x-3.2移植到到android步骤及问题定位

本篇名言:所有主体客体及人类文化活动之全部 。[杜威]


1. 先安装jdk1.7,或者jre7,并且配置好java环境变量。

2. 然后准备一套android的开发环境,分别下载android的sdk和ndk。SNK路径环境变量设置如下

    NDK_ROOT=(你NDK解压到的目录)

3. 下载python2.7.x系列(python太新貌似不行)

4 在需要发布到android的cocos2d代码中找到proj.android文件夹,再找到jni文件夹,可以看到这里面有两个.mk文件,打开android.mk,这里面记录了哪些文件需要编译,以及一些其他信息。

需要修改,增加对应的.c文件,删除不必要的.c文件。LOCAL_SRC_FILES :=

    修改修改增加头文件路径

 

    注意几个问题:

第一:有些函数不嗯能够通过build_native.py进行编译成java代码

point::point,需要改成point

Size::size需要改成size

     第二:找不到头文件cocos-ext.h需要修改

LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \

 $(LOCAL_PATH)/../../cocos2d/extensions

LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

$(call import-module,extensions)

     第三:

有些函数需要重新写一下如std::to_string(count)不能编译,java 没有该函数修改如下

    charcountBuf[16] = "";

sprintf(countBuf,"%d", money);

automoneyText = countBuf;

第四:

如报错:multiple definition of 'vtable forAppDelegate'

原因是LOCAL_SRC_FILES :=文件中同一个文件加入了二次

第五:

如报错:multiple definition of'AppDelegate::~AppDelegate()'

删除cocos2dx 主函数中的 AppDelegate 析构函数


本人魔兽塔防增加的如下

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/extensions

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/external

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d/cocos

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/2d

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/2d/render

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/2d/gui

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/2d/base

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d/cocos/2d/physics

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/math

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/base

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/audio/include

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d/cocos/editor-support

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/network

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/ui

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/cocos/physics

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d/cocos/storage

LOCAL_C_INCLUDES +=$(LOCAL_PATH)/../../cocos2d/chipmunk/include/chipmunk

LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d

 

        $(callimport-add-path,$(LOCAL_PATH)/../../cocos2d)

        $(callimport-add-path,$(LOCAL_PATH)/../../cocos2d/external)

        $(callimport-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)

 

       LOCAL_WHOLE_STATIC_LIBRARIES += cocosbuilder_static

       LOCAL_WHOLE_STATIC_LIBRARIES += spine_static

       LOCAL_WHOLE_STATIC_LIBRARIES += cocostudio_static

       LOCAL_WHOLE_STATIC_LIBRARIES += cocos_network_static

       LOCAL_WHOLE_STATIC_LIBRARIES += cocos_extension_static

$(call import-module,editor-support/cocosbuilder)

        $(callimport-module,editor-support/spine)

        $(callimport-module,editor-support/cocostudio)

        $(callimport-module,network)

        $(callimport-module,extensions)

 

 

 

5 编译方法是使用命令行进入要编译的工程下的proj.android文件夹,然后运行build_native.py这个文件。

6 在eclipse 中创建android project from existing code.

选择WIN32工程目录下的proj.android文件夹,点击完成。

勾选COPY。

7 回到

COCOS2DX项目  \TestGame\cocos2d\cocos\2d\platform\android\java\src目录下,将org文件夹(整个文件夹)复制粘贴到android项目下的src文件下

(cocos2d路径\TestGame\proj.android\src),这个每次移植都是必须做的。选中项目,右键刷新。


注意:有时候需要重新导入一下lib库就好了。

如果有资源文件会自动进行COPY到ANDROID项目的ASSETS中。

8. 最后在ECLIPS中修改自己写的工程

完毕

邮箱:[email protected]

微信公众号:HopToad

欢迎联系关注


你可能感兴趣的:(android,jni,NDK,移植,cocos2d-x)