I have been creating a game which can run on both Windows and Android. I already have a working android build but decided to add save and load feature to both the Android and Windows builds. For this I used XML serialization as described here.
My job is to read from an XML file like a database and for this purpose I also use a XML editor. The editor shows that encoding is done as Windows-1252
<?xml version="1.0" encoding="Windows-1252"?>
So, while building my Windows build I had to include 2 dll files into Assets/Plugins folder as mentioned here. This made the Windows build run as I wanted. The problem starts when I try to run the Android build. It shows the same problem which occurred to me in the Windows build when I didn’t include the dll’s.
So, my question is if there is a quick way to use the 2 dll’s mentioned in the link in the android build, if possible, without recompiling the dll’s. Is there any other workaround(Will changing encoding format do?)
So, I will be answering my own question here. After a lot of research I found that the problem was neither with the dll’s or with the encoding. The required file was just not found by Android. Since Android uses an archive to ship builds, all the files are zipped up in the archive. To make sure that your predefined file is shipped with the build, make a folder called StreamingAssets inside the Assets folder as mentioned here. This will make your file present in the apk archive.
Now after you install the apk file in your android system, your required file does not get automatically installed. You have to do explicitly. You have to use the WWW class inside your project to transfer the required file to the required directory like below.
using UnityEngine;
using System.Collections;
using System.IO;
public class Copyxml : MonoBehaviour
{
WWW www;
#if UNITY_ANDROID && !UNITY_EDITOR
void Start ()
{
StartCoroutine("Downloader");
}
IEnumerator Downloader ()
{
www = new WWW ("jar:file://" + Application.dataPath + "!/assets/XMLFILE.xml");
yield return www;
if (www.isDone == true)
{
File.WriteAllBytes (Application.persistentDataPath + "/XMLFILE.xml", www.bytes);
}
}
#endif
}
And you are done!!
Answered for the convenience of others.