NDK学习(4) 给cocos加入lua

lua的编译方式后面会介绍,今天直接说在cocos里使用lua遇到的坑......


有2种方法,一种是连带lua源码一起丢进去和cocos一起编译,另外种是用已经编译好的lua静态文件和cocos一起编译,

下面一一介绍。。。。顺便说说遇到的坑


方式1:lua源码 + cocos一起编译,主要是Android.mk的编写


Android.mk:
<pre name="code" class="html">LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)LOCAL_MODULE := luaLOCAL_SRC_FILES := lapi.c lauxlib.c lbaselib.c lcode.c ldblib.c ldebug.c ldo.c ldump.c lfunc.c lgc.c linit.c liolib.c llex.c lmathlib.c lmem.c loadlib.c lobject.c lopcodes.c loslib.c lparser.c lstate.c lstring.c lstrlib.c ltable.c ltablib.c ltm.c lundump.c lvm.c lzio.cinclude $(BUILD_STATIC_LIBRARY)
<span style="color:#ff0000;">LOCAL_PATH := $(call my-dir)</span>
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_sharedLOCAL_MODULE_FILENAME := libcocos2dcppLOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../ClassesLOCAL_STATIC_LIBRARIES := cocos2dx_static LOCAL_WHOLE_STATIC_LIBRARIES += luainclude $(BUILD_SHARED_LIBRARY)$(call import-module,./prebuilt-mk)
 

lua源码放在jni目录

这段语法的意思是 先编译lua的源代码,模块名命名为lua,

一般以LOCAL_PATH开头....................include$() 结尾

这段代码说明有2段编译(2段LOCAL_PATH开头....................include$() 结尾)

但是注意红色部分...红色部分导致无法编译,如果网上资料查的多,都知道红色部分是正确的呢,但是必须去掉他才能通过编译!


方式2:

LOCAL_PATH:= $(call my-dir)    
# 需要把静态库导入   
include $(CLEAR_VARS)    
LOCAL_MODULE    := lua    
LOCAL_SRC_FILES := liblua.a    
include $(PREBUILT_STATIC_LIBRARY)


<span style="color:#ff0000;">LOCAL_PATH:= $(call my-dir)   </span> 
include $(CLEAR_VARS)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp

LOCAL_SRC_FILES := hellocpp/main.cpp \
                   ../../Classes/AppDelegate.cpp \
                   ../../Classes/HelloWorldScene.cpp   

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

LOCAL_STATIC_LIBRARIES := cocos2dx_static  

 LOCAL_WHOLE_STATIC_LIBRARIES += lua
include $(BUILD_SHARED_LIBRARY)

$(call import-module,./prebuilt-mk) 
 

同样注意红色那一行,这部分应该删除掉......





上传图片

相关文章

操作步骤 1、创建cocos2d-x工程 2、新建 Scene1.cpp Scene1.h Scene1.h代码 #ifndef __SCENE1_H__#defi...
开发环境:OS(WINDOWS 8.1 X64 企业版) cocos2d-x 2.2.1 vs2010 想给vs安装上cocos的模版,执行Install...
把创建项目做成一个批处理,当创建项目时可以省时省力很多。 操作步骤 1、在 E:cocos2d-x-2.2.1toolspr...
https://www.cnblogs.com/JiaoQing/p/3906780.html 四个响应函数 1 EventListenerPhysicsContact* evC...
转载于 http://www.cnblogs.com/kenkofox/p/3926797.html 熟悉js的dom事件或者flash事件的,基本都能立...
ScrollView(滚动容器)加载大量item时会导致游戏界面的卡顿,严重时整个界面会出现卡死的情况。最近项...