手动NDK编译的方法:
用NDK来手动编译Cocos2d-x的例子 HelloCPP。
(1) 下载最新的NDK,ADT。下载解压安装后设置好NDK-BUILD的环境变量
(2) 切换到Cocos2d-x HellpCPP例子里面的Android工程,jni目录。
需要修改jni里面的Android.mk和Application.mk
Android.mk需要添加Cocos2d-x的路径,如下
$(call import-add-path, F:\Cocos2d\cocos2d-2.1rc0-x-2.1.2-hotfix\cocos2d-2.1rc0-x-2.1.2) \ $(call import-add-path, F:\Cocos2d\cocos2d-2.1rc0-x-2.1.2-hotfix\cocos2d-2.1rc0-x-2.1.2\cocos2dx\platform\third_party\android\prebuilt) \
LOCAL_PATH := $(call my-dir) $(call import-add-path, F:\Cocos2d\cocos2d-2.1rc0-x-2.1.2-hotfix\cocos2d-2.1rc0-x-2.1.2) \ $(call import-add-path, F:\Cocos2d\cocos2d-2.1rc0-x-2.1.2-hotfix\cocos2d-2.1rc0-x-2.1.2\cocos2dx\platform\third_party\android\prebuilt) \ include $(CLEAR_VARS) LOCAL_MODULE := hellocpp_shared LOCAL_MODULE_FILENAME := libhellocpp LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/HelloWorldScene.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static include $(BUILD_SHARED_LIBRARY) $(call import-module,CocosDenshion/android) \ $(call import-module,cocos2dx) \ $(call import-module,extensions)
在Application.mk中需要添加Android的版本号,不然会出现 找不到gle.h 等错误
APP_PLATFORM := android-8
APP_STL := gnustl_static APP_CPPFLAGS := -frtti -DCOCOS2D_DEBUG=1 APP_PLATFORM := android-8
然后在jni目录使用命令
ndk-build
来编译
一定要把工程的资源文件拷贝到Android文件夹的Assest文件夹下面