首先调整屏幕适配
//glview->setFrameSize(800,480);去掉,在真机上不需要,屏幕大小已经有了修改为ResolutionPolicy::EXACT_FIT :保证了设计区域完全铺满屏幕,但是可能会出现图像拉伸
glview->setDesignResolutionSize(800,480,ResolutionPolicy::EXACT_FIT);
1、导入工程到Eclipse
打开eclipse,在新建项目时选择“File->New->Other->Android/Android Project from Existing Code”,选择上步提到的proj.android将项目导入eclipse。
2、设置项目配置信息
(1)在项目上点“属性”-android-Project Build Target 选择相应android版本,我的是android4.4
(2)右键->Build Path->Config Build Path,在source下可以看到libcocos2d的路径是错误的,中间多了一个“2d”。将其改回正确路径。
3、解决android项目库的加载
拷贝cocos2dx库文件,在源码目录 cocos2d\cocos\platform\android\java\src下 ,拷贝org目录文件放到proj.android\src 目录下
4、修改jni/android.mk 文件 和 Application.mk文件
LOCAL_PATH := $(call my-dir) 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 LOCAL_SRC_FILES := hellocpp/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/GameBaseScene.cpp \ ../../Classes/Item.cpp \ ../../Classes/Item_ball.cpp \ ../../Classes/Item_crab.cpp \ ../../Classes/Item_emergency.cpp \ ../../Classes/Item_fog.cpp \ ../../Classes/Item_strength_up.cpp \ ../../Classes/Item_stretcher.cpp \ ../../Classes/LanguageString.cpp \ ../../Classes/LotteryCard.cpp \ ../../Classes/MapChooseScene.cpp \ ../../Classes/MenuScene.cpp \ ../../Classes/RicherGameController.cpp \ ../../Classes/RicherPlayer.cpp \ ../../Classes/RouteNavigation.cpp \ ../../Classes/SeaScene.cpp \ ../../Classes/SplashScene.cpp \ ../../Classes/Util.cpp \ ../../Classes/PopupLayer/CocosToast.cpp \ ../../Classes/PopupLayer/PopupLayer.cpp \ ../../Classes/skill/SkillCard.cpp \ ../../Classes/stock/LineChart.cpp \ ../../Classes/stock/Stock.cpp \ ../../Classes/stock/StockCellCard.cpp \ ../../Classes/stock/VisibleRect.cpp \ ../../Classes/lottery/EllipseBy.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes \ $(LOCAL_PATH)/../../Classes/PopupLayer \ $(LOCAL_PATH)/../../Classes/skill \ $(LOCAL_PATH)/../../Classes/stock \ $(LOCAL_PATH)/../../Classes/lottery 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 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)修改Application.mk文件,APP_ABI := armeabi x86 ,
这样就可以编译生成x86 和 arm平台相关的so文件
5、进入cmd命令提示符,编译生成.so文件
注意首先要配置好NDK环境变量
运行richer\proj.android>build_native.py 开始编译 或者 在richer目下运行 cocos compile -p android 编译
在编译时出现了cocos-ext.h错误,找不到
修改为 #include "extensions/cocos-ext.h" 即可
6、在eclipse中刷新,产生apk安装包,测试运行
工程右键 "Android Tools"-"Export Signed Application Package..."—"Project Checks" 填写richer —-“create new keystore”
保存签名文件为richer.key,填写密码完毕后,进入下一步
Key creation,填写完毕 下一步
填写存放要生成apk的目录,点击完成。
这样就可以安装apk测试了
7、其他问题:
(1)打开Eclipse后导入android项目后,退出后再打开有时遇到java.lang.NullPointerException错误。
文件在proj.android下面 “.cproject” 删除
(2)找不到 float int 等定义的变量,测试发现是由于进行了注释,注释中可能存在了不应有的字符 或者编码格式不对导致的
这时去掉注释就可以了
如 LineChart.h
文件中如下的注释去掉,如果不去掉,总是报这几个变量没有定义
float spaceRatio ; //y轴间距系数
float leftRatioX; //x轴左侧间距系数
int maxValue1; //数据中的最大值
float layerHeight1 ; //图离底部的距离
apk下载:点击下载apk
未完待续..................