创建 cocos2d-x+lua for android 步骤

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()) 代码










posted on 2011-11-02 12:49  游戏开发:主席  阅读(9797)  评论(0编辑  收藏  举报

导航