No announcement yet.

XML Parsing Project works on PC Editor but not Android Devices

  • Filter
  • Time
  • Show
Clear All
new posts

    XML Parsing Project works on PC Editor but not Android Devices

    Hi, I am encountering an issue with my android apk not reading contents from my XML file. The entire project worked fine on the editor and there is no packaging error. Managed to Logcat the problem and zeroed down the error. Here is the parsing part of the code.

    std::string MyString(TCHAR_TO_UTF8(*(FPaths::GameDir() + "Content/XMLFiles/TestRead.xml")));
    std::ifstream file(MyString.c_str());
    std::stringstream buffer;
    buffer << file.rdbuf();
    std::string content(buffer.str());
    UE_LOG(YourLog, Warning, TEXT("contents of xml: %s"), *FString(content.c_str())); //<- This prints out the entire XML content fine on editor
    It seems like the Android device is not reading the XML file. I have check the obb and the XML file is stored in "Content/XMLFiles/TestRead.xml" of the game directory. So the XML file is indeed packaged within.

    Click image for larger version

Name:	XMLA.png
Views:	1
Size:	4.2 KB
ID:	1216307

    The Editor printed the content

    Click image for larger version

Name:	XMLB.png
Views:	1
Size:	10.2 KB
ID:	1216308

    But the packaged file failed to print the content.

    I am relatively new to mobile development and wish someone could shed some light on this matter. Much help is appreciated.

    You could do this with:

    FString MyFilePath = FPaths::GameContentDir() + TEXT("XMLFiles/TestRead.xml");
    FString Contents;
    if (FFileHelper::LoadFileToString(Contents, *MyFilePath))
       // do something with *Contents
    Make sure you mark XMLFiles directory to be packaged as "Additional Non-Asset Directories to Package" in the Packaging Project Settings (you need to expand the Packaging section to see it).


      Hi Chris!

      It worked! Thanks for the help! Do I have to update this thread to solved?