一、首先第一点要确定自己选择的 NDK 版本是否存在问题,是否与项目所需匹配 ,正常编译过程会自动选择默认的NDK 版本,但是这也会导致了libcocos2dcpp.so 库文件无法成功生成, 更改方法 ,可以在 android 下的 jni=》选择application,mk 文件 ,添加 如:NDK_TOOLCHAIN_VERSION = 4.9
下面给个application.mk大致配置方法:
APP_STL := c++_static
NDK_TOOLCHAIN_VERSION=clang
APP_CPPFLAGS := -frtti -DCC_ENABLE_CHIPMUNK_INTEGRATION=1 -std=c++11 -fsigned-char
APP_LDFLAGS := -latomic
APP_DEBUG := $(strip $(NDK_DEBUG))
ifeq ($(APP_DEBUG),1)
APP_CPPFLAGS += -DCOCOS2D_DEBUG=1
APP_OPTIM := debug
else
APP_CPPFLAGS += -DNDEBUG
APP_OPTIM := release
endif
NDK_TOOLCHAIN_VERSION = 4.9
二、第二点要考虑的是否把项目下的所有cpp文件都添加到了 android.mk文件下,是否有重复添加,并且要添加编译时 项目所需的SDK 库 和 所需要包含的 cocos2dx 库的 路径,还要加好说需要的头文件路径 比如: cocos2d/extensions 头文件等。
LOCAL_PATH := $(call my-dir)
############################################################################################################
# fmod (音频)#编译程序所需要的库
# fmodex
include $(CLEAR_VARS)
LOCAL_MODULE := fmodex
LOCAL_SRC_FILES := ../../Classes/sdk/fmod/android/api/lib/$(TARGET_ARCH_ABI)/libfmodex.so
include $(PREBUILT_SHARED_LIBRARY)
# fmodevent
include $(CLEAR_VARS)
LOCAL_MODULE := fmodevent
LOCAL_SRC_FILES := ../../Classes/sdk/fmod/android/fmoddesignerapi/api/lib/$(TARGET_ARCH_ABI)/libfmodevent.so
include $(PREBUILT_SHARED_LIBRARY)
############################################################################################################
include $(CLEAR_VARS)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/external)
$(call import-add-path,$(LOCAL_PATH)/../../cocos2d/cocos)
LOCAL_MODULE := cocos2dcpp_shared
LOCAL_MODULE_FILENAME := libcocos2dcpp
FILE_LIST := hellocpp/main.cpp
# sdk cpp代码的添加
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/sdk/fmod/*.cpp)
# 基础库 #cpp代码的添加
FILE_LIST += $(wildcard $(LOCAL_PATH)/../../Classes/*.cpp)
LOCAL_SRC_FILES := $(FILE_LIST:$(LOCAL_PATH)/%=%)
# 头文件路径
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes
LOCAL_C_INCLUDES += $(LOCAL_PATH)/../../cocos2d/extensions
############################################################################################################
# 静态库
LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static
LOCAL_WHOLE_STATIC_LIBRARIES += cocosdenshion_static
# LOCAL_WHOLE_STATIC_LIBRARIES += Box2d_static
# 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
# 第三方sdk 静态库
LOCAL_WHOLE_STATIC_LIBRARIES += libiconv_static
# LOCAL_WHOLE_STATIC_LIBRARIES += libsqlite3_static
############################################################################################################
# 动态库
# fmod(音频)
LOCAL_SHARED_LIBRARIES += fmodex
LOCAL_SHARED_LIBRARIES += fmodevent
############################################################################################################
include $(BUILD_SHARED_LIBRARY)
$(call import-module,.)
$(call import-module,audio/android)
# $(call import-module,Box2D)
# $(call import-module,editor-support/cocosbuilder)
# $(call import-module,editor-support/spine)
# $(call import-module,editor-support/cocostudio)
# $(call import-module,network)
$(call import-module,extensions)
############################################################################################################
# 第三方sdk
# 编码转换
$(call import-module,../Classes/sdk/libiconv)
# 数据库
# $(call import-module,../Classes/sdk/sqlite3)
############################################################################################################
###等等 等等。。。