博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建 cocos2d-x+lua for android 步骤
阅读量:6038 次
发布时间:2019-06-20

本文共 4711 字,大约阅读时间需要 15 分钟。

1 LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/http://www.cnblogs.com/libs/armeabi) \ 2     -L$(call host-path, $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx/platform/third_party/android/libraries) -lcurl \ 3     -lcocos2d \ 4     -lcocosdenshion \ 5     -llua

1: 按照普通方法创建工程

 

 

2:请注意修改 android/build_native.sh文件, RESOURCE_ROOT修改为$GAME_ROOT/Resource, 我的0.9.1版本自动生成的为$GAME_ROOT/Resources

 

3: 修改android/jni/Android.mk文件如下(红色字体)

1 LOCAL_PATH := $(call my-dir)  2     include $(CLEAR_VARS)  3  4  5     subdirs := $(addprefix $(LOCAL_PATH)/http://www.cnblogs.com/../,$(addsuffix /Android.mk, \  6                cocos2dx \  7                CocosDenshion/android \  8                lua/proj.android/jni \  9         )) 10     subdirs += $(LOCAL_PATH)/pyramid/Android.mk 11 12     include $(subdirs)

4:修改jni\helloworld\Android.mk中

LOCAL_C_INCLUDES := $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx/platform \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx/include \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx/lua_support \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/CocosDenshion/include \                    $(LOCAL_PATH)/http://www.cnblogs.com/../Classes \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/lua/lua \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/lua/tolua \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/lua/cocos2dx_support \                    $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/lua/CocosDenshion_support
1 LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/http://www.cnblogs.com/libs/armeabi) \ 2     -L$(call host-path, $(LOCAL_PATH)/http://www.cnblogs.com/http://www.cnblogs.com/cocos2dx/platform/third_party/android/libraries) -lcurl \ 3     -lcocos2d \ 4     -lcocosdenshion \ 5     -llua

5:修改jni\Application.mk

APP_MODULES := cocos2d cocosdenshion lua game
6:在android\src\org\cocos2dx\xxx\xx.java中修改:

1      static {    System.loadLibrary("cocos2d"); 2         System.loadLibrary("cocosdenshion"); 3         System.loadLibrary("lua"); 4         System.loadLibrary("game"); 5     }

7: 根据需要更改默认名字

脚本自动生成的是game库和hellowworld目录
a: 将目录jni/helloworld修改为自己的名字,比如: jni/pyramid
b: 修改 jni/Application.mk中的game为pyramid
c: 在android\src\org\cocos2dx\xxx\xx.java中  System.loadLibrary("game")  为          System.loadLibrary("pyramid")
d: 修改jni/Android.mk中如下: subdirs += $(LOCAL_PATH)/pyramid/Android.mk

 

8:需要注意一点就是Android.mk文件中

针对SRC和INC,其路径指定不一样,编译文件需要指定相对路径,而include文件需要指定绝对路径,比如:

1 PYRAMID_SRC_ROOT := http://www.cnblogs.com/../Classes 2 PYRAMID_INC_ROOT := $(LOCAL_PATH)/http://www.cnblogs.com/../Classes

9: 同时运行多个OS,比如windows、macos等,需要将build_native.sh文件转为unix格式

  在cygwin下运行 dos2unix build_native.sh

 

10:小技巧

(1)可以通过uname判断是在什么os下,方便设置路径

 

if [ $(uname -s) = "Darwin" ]; then     echo MacOs     ANDROID_NDK_ROOT=/Volumes/work/tools/android/android-ndk-r6b-macosx else     echo Cygwin     ANDROID_NDK_ROOT=/cygdrive/f/tools/Android/android-ndk-r5c fi

(2)由于编译时间较长,可以使用 growl来做提醒

 

windows下请下载: growl for windows

在build_native.sh最后加入:

1 if [ $(uname -s) = "Darwin" ]; 2 then 3     growlnotify -s -m :"ndk-build" $1" finish" 4 else 5     growlnotify /t:"ndk-build" $1" finish" 6 fi

调试中遇到的一些问题:

1:如果需要加入sqlite, 需要下载最新的源代码(sqlite-amalgamation-3070800.zip),否则会报错误“undefined reference to `fdatasync'”,
同时在Android.mk文件中加入:
LOCAL_CFLAGS :=-Wall -D_FILE_OFFSET_BITS=64 -DUSE_OPEN -DUSE_THREAD
不加flags也会报undefined reference to `fdatasync'错误
2: How to increase storage for Android Emulator? (INSTALL_FAILED_INSUFFICIENT_STORAGE)
To summarize (and clarify), in Eclipse, go to "Debug Configurations". You can find that in the drop-down under the "debug" icon. Select "target", and select a preferred emulator target to launch. Then under "additional emulator command line options," add this:
-partition-size 1024
Another note to make: You must right click on the project you want to run in eclipse -> Run->Run Configuration->Select Project->Target ->scroll down->add -partition-size 1024 to additional Em options-> then run the project from eclipse
3: Eclipse出现android Multiple markers at this line 错误:
这是由于JDK1.5的缘故,只需要将Compiler compliance level修改为1.6即可.
此处可能需要在两个地方修改
 (1) Eclipse的Window-Preferences->Java->Compiler
(2)Eclipse的Project->Properties->Java Compiler

 

4:require 找不到需要的文件时, 防止弹出错误对话框

修改CCFileUtils_android.cpp文件 getFileData 函数,屏蔽 CCMessageBox(msg.c_str(), title.c_str()) 代码

转载于:https://www.cnblogs.com/GameDeveloper/archive/2011/11/02/2232921.html

你可能感兴趣的文章
Java break continue return 的区别
查看>>
算法(Algorithms)第4版 练习 1.3.4
查看>>
jquery easyUI checkbox复选项获取并传后台
查看>>
浅析NopCommerce的多语言方案
查看>>
设计模式之简单工厂模式
查看>>
C++中变量的持续性、链接性和作用域详解
查看>>
2017 4月5日上午
查看>>
Google Chrome开发者工具
查看>>
第一阶段冲刺报告(一)
查看>>
使用crontab调度任务
查看>>
【转载】SQL经验小记
查看>>
zookeeper集群搭建 docker+zk集群搭建
查看>>
Vue2.5笔记:Vue的实例与生命周期
查看>>
论JVM爆炸的几种姿势及自救方法
查看>>
联合体、结构体简析
查看>>
使用throw让服务器端与客户端进行数据交互[Java]
查看>>
java反射与代理
查看>>
深度分析Java的ClassLoader机制(源码级别)
查看>>
微服务架构选Java还是选Go - 多用户负载测试
查看>>
我的友情链接
查看>>