Hello,
just to clarify: I am aware, that this question has been asked quite a few times, but so far, none of the solutions proposed worked for me and my specific case. So as I am pretty much at wits end here, I hope that someone out there might be able to help me.
My setup:
I have a leveleditor-scene, which is simply there to create levels. Once created, these are then saved as XML-files in my project.
The destinationpath is in this example “Assets/StreamingAssets/XML/Difficulty01/level_data1.xml”.
These XML-files are then being read in my actual game-scene to generate levels at runtime. On my PC this works perfectly. But once I try this on Android it doesn’t anymore.
Now I know, that i can’t use the same method on Android as on the PC. Files in the .apk are compressed, so to read and deserialize my XML-files I first have to “unzip” them.
So on Android I try something like this:
if (Application.platform == RuntimePlatform.Android)
{
// Android
string realPath = Application.streamingAssetsPath + "/XML/Difficulty01/level_data1.xml";
reader = new WWW (realPath);
while(!reader.isDone)
{
}
XmlSerializer serializer = new XmlSerializer(typeof(Levels));
FileStream stream = new FileStream(reader.url, FileMode.Open);
if(stream != null)
{
lvls = serializer.Deserialize(stream) as Levels;
}
stream.Close();
}
So I try to feed the path of my XML-File to my “WWW reader” to access my zipped files and then try to proceed to deserialize what’s at the end of that path. The problem is, that my Filestream doesn’t find anything at the path that i feed to him (being reader.url).
The path that is behind the reader.url on Android is the following:
“jar:file:///data/app/com.DefaultCompany.PuzzleGame-1/base.apk!/assets/XML/Difficulty01/level_data1.xml”
Where as I don’t really know why there is a “-1” appended to my BundleIdentifier.
Anyways, I looked into my .apk file and there is an XML-file at the path “assets/XML/Difficulty01/level_data1”.
Why can’t i seem to access that file then? is there something wrong with my approach? Is the path in reader.url somehow wrong? I really hope someone here sees my mistake, because i have been trying multiple things for the past week. to no avail.