移植步骤 :
1:ndk 环境搭建 linux环境
2:Android.mk文件的编写:
四个核心文件:
1):android/jni/Application.mk
2): android/jni/Android.mk
subdirs := $(addprefix $(LOCAL_PATH)/../../../,$(addsuffix /Android.mk, \
cocos2dx \
CocosDenshion/android \
Box2D \
))
3):android/jni/helloworld/Android.mk文件
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := helloworld_shared
LOCAL_MODULE_FILENAME := libhelloworld
LOCAL_SRC_FILES := main.cpp
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../Classes
LOCAL_STATIC_LIBRARIES := png_static_prebuilt
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES := game_logic_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_SHARED_LIBRARIES := cocosdenshion_shared box2d_shared
include $(BUILD_SHARED_LIBRARY)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)
4) Classes/Android.mk
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := game_logic_static
LOCAL_MODULE_FILENAME := libgame_logic
#获取制定目录下的所有的cpp文件
cppfilestemp1 := $(shell find $(LOCAL_PATH)/../src -type d)
cppfilestemp2 := $(shell find $(cppfilestemp1) -name *.cpp)
cppfilestemp3 := $(sort $(cppfilestemp2))
cppfiles := $(subst $(LOCAL_PATH)/,,$(cppfilestemp3))
cppfilestemp111 := $(shell find $(LOCAL_PATH)/../lib_json -type d)
cppfilestemp222 := $(shell find $(cppfilestemp111) -name *.cpp)
cppfilestemp333 := $(sort $(cppfilestemp222))
cppfilesss := $(subst $(LOCAL_PATH)/,,$(cppfilestemp333))
LOCAL_SRC_FILES := \
AppDelegate.cpp \
GLES-Render.cpp \
$(cppfiles) \
$(cppfilesss)
LOCAL_C_INCLUDES := $(LOCAL_PATH) \
$(LOCAL_PATH)/../../cocos2dx \
$(LOCAL_PATH)/../../cocos2dx/platform \
$(LOCAL_PATH)/../../cocos2dx/include \
$(LOCAL_PATH)/../../cocos2dx/lua_support \
$(LOCAL_PATH)/../../CocosDenshion/include \
$(LOCAL_PATH)/../src/include \
$(LOCAL_PATH)/../lib_json/include
LOCAL_STATIC_LIBRARIES += xml2_static_prebuilt
LOCAL_STATIC_LIBRARIES += jpeg_static_prebuilt
LOCAL_WHOLE_STATIC_LIBRARIES += cocos2dx_static
LOCAL_SHARED_LIBRARIES := cocosdenshion_shared box2d_shared
include $(BUILD_STATIC_LIBRARY)
$(call import-module,cocos2dx/platform/third_party/android/modules/libpng)
$(call import-module,cocos2dx/platform/third_party/android/modules/libxml2)
$(call import-module,cocos2dx/platform/third_party/android/modules/libjpeg)
3:java代码调用:
static {
System.loadLibrary("cocosdenshion");
System.loadLibrary("box2d");
System.loadLibrary("helloworld");
}
☞: LOCAL_SRC_FILES += $(subst $(LOCAL_PATH)/,,$(shell find $(LOCAL_PATH)/../../../Classes -name "*.cpp" -print))