I’ve been trying to get this fixed for several nights! I tried to Google and go through this forum for answers. I’ve tried using Application.persistantDataPath, Application.dataPath, Application.streamingAssetsPath and also tried using the WWW method of reading my file and still cannot get my game to read the files.
My old code worked on my PC but on Android, nothing. Both files are XML files, they are in my root directory, Assets/.xml and they need to be read and written. I’m sure if I get one file to read and written to correctly I can know how to deal with the second XML file. So the GameState.XML file is this.
I’m able to compile and run the game in the Editor. Not on the Android device.
I’m certain the line causing the problem is:
XmlReader reader = XmlReader.Create(path1);
Because I have a print( ) statement after that line of code above, it does not show up in the logs. So that’s why I strongly believe it’s that line causing the problem. I’ve done more research on finding a solution to this type of problem and haven’t found it. I just recently deleted the temp files I had and still doesn’t work. Someone talked about file permissions and not sure how to check that.
The log output that I get is:
05-06 02:02:42.918: I/Unity(25807):
05-06 02:02:42.918: I/Unity(25807): (Filename: C Line: 0)
05-06 02:02:43.058: I/Unity(25807): UriFormatException: URI scheme must start with a letter and must consist of one of alphabet, digits, '+', '-' or '.' character.
05-06 02:02:43.058: I/Unity(25807): at System.Uri.Parse (UriKind kind, System.String uriString) [0x00020] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/System/System/Uri.cs:1351
05-06 02:02:43.058: I/Unity(25807): at System.Uri.ParseUri (UriKind kind) [0x00000] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/System/System/Uri.cs:1215
05-06 02:02:43.058: I/Unity(25807): at System.Uri..ctor (System.String uriString, Boolean dontEscape) [0x00064] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/System/System/Uri.cs:209
05-06 02:02:43.058: I/Unity(25807): at System.Uri..ctor (System.String uriString) [0x00000] in <filename unknown>:0
05-06 02:02:43.058: I/Unity(25807): at System.Xml.XmlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) [0x00064] in /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/System.XML/System.Xml/XmlResolver.cs:66
05-06 02:02:43.058: I/Unity(25807): at System.Xml.XmlUrlResolver.ResolveUri (System.Uri baseUri, System.String relativeUri) [0x00000] in /Users/
I probably didn’t use the term root directory correctly, I simply Build the project and have it automatically installed on my device and it starts up immediately. I have Developer Build and Script Debugging checked. Here’s the exact location of the GameState.XML file.
The log file from the android device is basically saying it does not have a c:\ drive. Which I am 100% certain is correct. The documentation for StreamingAssets tells you what the URI needs to be:
You’re trying to access the file directly without accounting for the storage format.
[quIt’s always best to use Application.streamingAssetsPath to get the location of the StreamingAssets folder, it will always point to the correct location on the platform where the application is running.[/quote]
Secondly, you’re writing as well as reading, right? If so then a resource baked into the build won’t work. To write the files you’ll have to copy them to the app’s persistent data path, and use those copies as per any normal file.
S suggest hitting up the docs to learn about how resources work, it might clear some things up for you. In short, stuff that’s in the project folder is not just copied over as files when you do a build. They’re baked into some platform-specific binary format which may or may be stored differently on each platform.
Note that on Android, the files are contained within a compressed .jar file (which is essentially the same format as standard zip-compressed files). This means that if you do not use Unity’s WWW class to retrieve the file then you will need to use additional software to see inside the .jar archive and obtain the file."
Hi, after almost 4 years, did anyone find the solution to this? I tried what is written in Unity’s documentation, i.e.
path = “jar:file://” + Application.dataPath + “!/assets/”;
but am unable to get a result. However Mr. Sam777’s answer confuses me more as I don’t know how to use WWW class in Unity… Can anyone please help?
The www class does deal with the zip compression of the files that are in the streaming asset path inside the jar file / app.
You can just use Application.streamingAssetsPath to get the correct path.
public string url = [URL='https://docs.unity3d.com/ScriptReference/Application-streamingAssetsPath.html']Application.streamingAssetsPath[/URL] + FilenameWitchExtention;
IEnumerator Start()
{
using (WWW www = new WWW(url))
{
yield return www;
//use www.bytes to get access the bytes of the file.
// if the file is a image you can use www.texture to get acess to the image texture.
}
}