tinyXml crashes on adnroid

tinyXml crashes on adnroid
0.0 0


I’m trying to use tinyxml in my cocos2d-x-2.0.1 project. With win 32 it’s ok, but on android app is closed with no errors.
I used this code:

TiXmlDocument doc( "main.xml" ); doc.LoadFile(); TiXmlElement* pElem; pElem = doc.FirstChildElement("Hello"); const char * text = pElem->GetText(); CCLog("%s" , text);


<?xml version="1.0" ?> <Hello>Looool</Hello>

In Android.mk:

LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := game_shared LOCAL_MODULE_FILENAME := libgame LOCAL_SRC_FILES := helloworld/main.cpp \ ../../Classes/AppDelegate.cpp \ ../../Classes/tinyxml/tinystr.cpp \ ../../Classes/tinyxml/tinyxml.cpp \ ../../Classes/tinyxml/tinyxmlerror.cpp \ ../../Classes/tinyxml/tinyxmlparser.cpp \ ../../Classes/HelloWorldScene.cpp LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../Classes LOCAL_WHOLE_STATIC_LIBRARIES := cocos2dx_static cocosdenshion_static LOCAL_WHOLE_STATIC_LIBRARIES += box2d_static include $(BUILD_SHARED_LIBRARY) $(call import-module,CocosDenshion/android) $(call import-module,cocos2dx) $(call import-module,Box2D)

  1. Make sure your file is in Resources. Check you really have it in your apk.
  2. You need to use CCFileUtils::fullPathFromRelativePath for getting file names for opening files. As far as I know it doesn’t make sense on Android, but anyway…
  3. CCLog’s output is buffered so you possibly just don’t see your message before app quits. Try using “s\n" instead of "s” to force buffer output.


I tryed all you wrote. Could you run tinyxml on android? Please, send example of code.


The crash happens because it fails to load the file.

A solution to this is to load the file with cocos2d-x file utilities and pass it to tinyxml parser.

TiXmlDocument doc( test.xml );
unsigned long buffer_size = 0;
unsigned char* file_buffer = CCFileUtils::sharedFileUtils()->getFileData(CCFileUtils::sharedFileUtils()->fullPathFromRelativePath(doc.Value()), “r”, &buffer_size);
doc.Parse((const char*)file_buffer);@

I know this is a late reply but the thread didn’t offer a solution yet.