Cocos2d-x & NDK

------------------------

cocos2d-2.1beta3-x-2.1.0

android-ndk-r8c

------------------------

1.设置环境变量

cocos2d-2.1beta3-x-2.1.0\create-android-project.bat

set_CYGBIN=E:\software\dev\Android\cygwin\bin

set_ANDROIDTOOLS=E:\software\dev\Android\android-sdk-windows\tools

set_NDKROOT=E:\software\dev\Android\android-ndk-r8c

2.在新生成工程中设置环境变量

cocos2d-2.1beta3-x-2.1.0\Cocos2dxTest\proj.android

exportNDK_ROOT=/cygdrive/e/software/dev/Android/android-ndk-r8c/

3.安装GNUmake

Cygwin_setup.exe-》搜索make-》选择GNUmake安装

AllDefault-》DevelDefault-》make:TheGNUversionofthe'make'utility-》点击“Skip”选择版本安装

4.权限错误

cc1plus.exe:fatalerror:jni/hellocpp/main.cpp:Permissiondenied

工程目录-》右键-》属性-》安全-》所有用户-》完全控制-》高级-》更改权限-》使用可从此对象继承的权限替换所有子对象权限

5.引用cocos2d-2.1beta3-x-2.1.0\cocos2dx\platform\android\java错误“Cocos2dxActivitycannotberesolvedtoatype”

cocos2d-2.1beta3-x-2.1.0\Cocos2dxTest\proj.android\project.properties中会记录引用的资源:android.library.reference.1=../../cocos2dx/platform/android/java

可以把cocos2d-2.1beta3-x-2.1.0\cocos2dx\platform\android\java当做一个工程导入eclipse和Cocos2dxTest并列

6.OpenGLES版本问题

系统方面,从Android2.2开始支持OpenGLES2.0,但还需要硬件支持。

OpenGLES2.0:cocos2d-2.1beta3-x-2.1.0

OpenGLES1.1:cocos2d-1.0.1-x-0.13.0-beta

---------------------------

cocos2d-1.0.1-x-0.13.0-beta

android-ndk-r8c

---------------------------

7.资源错误

DescriptionResourcePathLocationType

error:Error:Noresourcefoundthatmatchesthegivenname(at'icon'withvalue'@drawable/icon').AndroidManifest.xml/MyCocos2dxline9AndroidAAPTProblem

AndroidManifest.xml中

<applicationandroid:label="@string/app_name"android:icon="@drawable/icon">

改为

<applicationandroid:label="@string/app_name"android:icon="@drawable/ic_launcher">

8.代码修改后每次都全部编译问题

android-ndk-r8c\build\core\definitions.mk

大约289行,$1:$$(__ndk_file_dir),改为:$1:|$$(__ndk_file_dir),r8c版本

9.win7下重新编译后assets目录下的文件访问权限问题

修改cocos2d-1.0.1-x-0.13.0-beta\BombCocos2dx\android\build_native.sh,将以下内容注释掉,然后从Resources目录手工复制相关资源到assets目录。

# make sure assets is exist
#if [ -d $GAME_ANDROID_ROOT/assets ]; then
#    rm -rf $GAME_ANDROID_ROOT/assets
#fi

#mkdir $GAME_ANDROID_ROOT/assets

# copy resources
#for file in $RESOURCE_ROOT/*
#do
#    if [ -d $file ]; then
#        cp -rf $file $GAME_ANDROID_ROOT/assets
#    fi
#
#    if [ -f $file ]; then
#        cp $file $GAME_ANDROID_ROOT/assets
#    fi
#done

10.模拟器经常连不上

DeviceDisconnected

window->ShowViews->device->viewmenu->Resetadb

11.getdatafromfile(assets/)failed

cocos2d-1.0.1-x-0.13.0-beta的bug

const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType) {
return "";
}

改为

const char* CCFileUtils::fullPathFromRelativePath(const char *pszRelativePath, ccResolutionType *pResolutionType) {
return pszRelativePath;
}

12.新增一个类,报undefinedreferenceto...错误

cocos2d-1.0.1-x-0.13.0-beta\MyProject\android\jni\Android.mk

增加新加的类

13.读取xml文件

参考Himi的xml读取方案。但是依赖于cocos2d-x新版本,如果使用cocos2d-1.0.1-x-0.13.0-beta,需要修改如下文件:

E:\software\dev\cocos2d\cocos2d-1.0.1-x-0.13.0-beta\cocos2dx\include\CCString.h

增加以下方法:

/** get the C string */
    const char* getCString() const 
    {
    	return m_sString.c_str();
    }

14.触摸报错

error:'classcocos2d::CCTouch'hasnomembernamed'view'

CCPointlocation=touch->locationInView(touch->view());

改为

CCPointlocation=touch->locationInView();

15.Cygwinfork错误

2[main]sh3132child_info_fork::abort:E:\software\dev\Android\cygwin\bin\cygiconv-2.dll:Loadedtodifferentaddress:parent(0x490000)!=child(0x2F0000)

/cygdrive/e/software/dev/Android/android-ndk-r8c/ndk-build:fork:Resourcetemporarilyunavailable

因为Cygwin在Windows下对fork()无法完全模拟,所以有的时候会出现问题,重新启动操作系统即可。

16.AndroidNDK错误

/cygdrive/e/software/dev/Android/android-ndk-r8c/build/core/add-application.mk:128:AndroidNDK:WARNING:APP_PLATFORMandroid-14islargerthanandroid:minSdkVersion7in./AndroidManifest.xml

Eclipse3.7&Eclipse4.2:Window->Preferences->C/C++->Build->Settings

Eclipse3.6:Window->Preferences->C/C++->Build

选择CDTGNUC/C++ErrorParser

在ErrorParseroptions中最上面添加如下内容:

Severity:Warning

Pattern:(.*?):(\d+):AndroidNDK:WARNING:(.*)

File:$1

Line:$2

Description:$3

17.提示如下错误

DescriptionResourcePathLocationType

E:\software\dev\cocos2d\cocos2d-1.0.1-x-0.13.0-beta\MyProject\android/build_native.sh:line7:$'\r':commandnotfoundMyProjectC/C++Problem

因为Windows下的换行是<LF><CR>,Linux下是<LF>,Mac下是<CR>。在Cygwin下执行如下即可:

$dos2unixbuild_native.sh

dos2unix:convertingfilebuild_native.shtoUnixformat...

18.CDT8.0.2forEclipseIndigo

http://download.eclipse.org/tools/cdt/releases/indigo

19.莫名其妙出现大量如下错误

DescriptionResourcePathLocationType

Type'std::string'couldnotberesolvedMyClass.h/MyProject/MyProject_Classesline40SemanticError

有很多类似的“couldnotberesolved”错误

可能是Eclipse的bug,回退到Eclipse3.6sr2解决问题

https://bugs.eclipse.org/bugs/show_bug.cgi?id=353719

---------------------------------------------------

PureMVCC++不支持Android

https://code.google.com/p/libpuremvc/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=3

---------------------------------------------------

20.使用puremvc-cpp-multicore

Mingw32中运行:mingw32-make-fmakefile.mgw

mingw32-make-fmakekfile.mgwDEBUG=1(DEBUG版)

报如下错误:

include/PureMVC/Interfaces/IAggregate.hpp:36:21: error: 'unique_ptr' in namespace 'std' does not name a type

修改makefile.mgw

CXX = g++ 改为 CXX = g++ -std=c++0x

报错:gcc:error:CreateProcess:Nosuchfileordirectory

PATH环境变量中添加:E:\software\dev\MinGW\libexec\gcc\mingw32\4.6.2

报错:gcc:fatalerror:-fuse-linker-plugin,butliblto_plugin-0.dllnotfound

改为在Cygwin中安装mingw-gcc-g++,运行正常。

21.通过Cygwin+NDK编译puremvc出现问题

改为使用MinGW,报错:

non-numericsecondargumentto`wordlist'function:'

需要修改__gmsl文件的第512行

把nt_encode=$(__gmsl_tr1)$(wordlist1,$1,$(__gmsl_input_int))

改成:

int_encode=$(__gmsl_tr1)$(wordlist1,$(words$1),$(__gmsl_input_int))即可。

PATH:E:\software\dev\MinGW\bin;E:\software\dev\MinGW\libexec\gcc\mingw32\4.6.2;E:\software\dev\MinGW\msys\1.0\bin;

路径:build_native.sh中/cygwin/e改为/e

22.eclipse换个机器有些插件就不好使了

清除eclipse\configuration\org.eclipse.update重新启动eclipse

另外,有些插件依赖于jdk1.6,比如ADT

参考:

设置开发环境:http://www.jesusbosch.com/2012/06/how-to-set-up-android-and-win32-cocos2d.html

http://www.raywenderlich.com/11283/cocos2d-x-for-ios-and-android-getting-started

pleasedefineNDK_ROOT:http://blog.csdn.net/snakewarhead/article/details/8223169

每次只编译修改的文件:http://cn.cocos2d-x.org/bbs/forum.php?mod=viewthread&tid=10043

Eclipse连不上模拟器:http://www.cnblogs.com/over140/archive/2010/08/06/1793264.html

http://www.cocos2d-x.org/boards/6/topics/9944

http://blog.molioapp.com/2011/11/openfeint-and-admob-integrated-with.html

支持多分辨率:http://www.himigame.com/android-game/799.html

Himixml:http://www.himigame.com/iphone-cocos2dx/694.html

CygwinFAQ:http://cygwin.com/faq-nochunks.html#faq.using.fixing-fork-failures

AndroidNDK问题:http://code.google.com/p/android/issues/detail?id=39752

相关推荐