NDK學(xué)習(xí)之如何給cocos加入lua
lua的編譯方式后面會介紹,今天直接說在cocos里使用lua遇到的坑......
有2種方法,一種是連帶lua源碼一起丟進(jìn)去和cocos一起編譯,另外種是用已經(jīng)編譯好的lua靜態(tài)文件和cocos一起編譯,
下面一一介紹。。。。順便說說遇到的坑
方式1:lua源碼 + ?cocos一起編譯,主要是Android.mk的編寫
Android.mk: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)
LOCAL_PATH?:=?$(call?my-dir)
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$() 結(jié)尾
這段代碼說明有2段編譯(2段LOCAL_PATH開頭....................include$() 結(jié)尾)
但是注意紅色部分...紅色部分導(dǎo)致無法編譯,如果網(wǎng)上資料查的多,都知道紅色部分是正確的呢,但是必須去掉他才能通過編譯!
方式2:
LOCAL_PATH:=?$(call?my-dir)???? #?需要把靜態(tài)庫導(dǎo)入??? include?$(CLEAR_VARS)???? LOCAL_MODULE????:=?lua???? LOCAL_SRC_FILES?:=?liblua.a???? include?$(PREBUILT_STATIC_LIBRARY)LOCAL_PATH:=?$(call?my-dir)????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)
同樣注意紅色那一行,這部分應(yīng)該刪除掉......