创建 cocos2d-x+lua for android 步骤
16lz
2021-12-04
1: 按照普通方法创建工程
5:修改jni\Application.mk
APP_MODULES := cocos2d cocosdenshion lua game
6:在android\src\org\cocos2dx\xxx\xx.java中修改:
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
(2)由于编译时间较长,可以使用 growl来做提醒
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
2:请注意修改 android/build_native.sh文件,RESOURCE_ROOT修改为$GAME_ROOT/Resource, 我的0.9.1版本自动生成的为$GAME_ROOT/Resources
3: 修改android/jni/Android.mk文件如下(红色字体)
LOCAL_PATH := $(call my-dir)include $(CLEAR_VARS)subdirs := $(addprefix $(LOCAL_PATH)/../../../,$(addsuffix /Android.mk, \ cocos2dx \ CocosDenshion/android \ lua/proj.android/jni \))subdirs += $(LOCAL_PATH)/pyramid/Android.mkinclude $(subdirs)
4:修改jni\helloworld\Android.mk中
LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \ $(LOCAL_PATH)/../../../../cocos2dx/platform \ $(LOCAL_PATH)/../../../../cocos2dx/include \ $(LOCAL_PATH)/../../../../cocos2dx/lua_support \ $(LOCAL_PATH)/../../../../CocosDenshion/include \ $(LOCAL_PATH)/../../../Classes \ $(LOCAL_PATH)/../../../../lua/lua \ $(LOCAL_PATH)/../../../../lua/tolua \ $(LOCAL_PATH)/../../../../lua/cocos2dx_support \ $(LOCAL_PATH)/../../../../lua/CocosDenshion_support
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \-L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl \-lcocos2d \-lcocosdenshion \-llua
5:修改jni\Application.mk
APP_MODULES := cocos2d cocosdenshion lua game
6:在android\src\org\cocos2dx\xxx\xx.java中修改:
static { System.loadLibrary("cocos2d"); System.loadLibrary("cocosdenshion"); System.loadLibrary("lua"); System.loadLibrary("game"); }
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文件需要指定绝对路径,比如:
PYRAMID_SRC_ROOT := ../../../ClassesPYRAMID_INC_ROOT := $(LOCAL_PATH)/../../../Classes
9: 同时运行多个OS,比如windows、macos等,需要将build_native.sh文件转为unix格式
在cygwin下运行 dos2unix build_native.sh
10:小技巧
(1)可以通过uname判断是在什么os下,方便设置路径
if [ $(uname -s) = "Darwin" ];thenecho MacOsANDROID_NDK_ROOT=/Volumes/work/tools/android/android-ndk-r6b-macosxelseecho CygwinANDROID_NDK_ROOT=/cygdrive/f/tools/Android/android-ndk-r5cfi
(2)由于编译时间较长,可以使用 growl来做提醒
windows下请下载: growl for windows
在build_native.sh最后加入:
if [ $(uname -s) = "Darwin" ];thengrowlnotify -s -m :"ndk-build" $1" finish"elsegrowlnotify /t:"ndk-build" $1" finish"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()) 代码
更多相关文章
- Android(安卓)XML文件解析
- ListView去掉分割线的几种方法
- Android下修改SeekBar样式
- Android(安卓)NDK工程创建与编译运行
- Android实现透明式状态栏
- 安卓手机常见名词解释
- Android(安卓)如何在XML文件中定义动画
- Android(安卓)资源文件中的符号含义与说明: @ ?
- android多播