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();
file.close();
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
doc.parse<0>(&content[0]);

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.

XMLA.png

The Editor printed the content

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! :slight_smile: Thanks for the help! Do I have to update this thread to solved?