Android build: Unauthorized access exception

When trying to build for Android I get the following error:

Error building Player: UnauthorizedAccessException: Access to the path /snip/Temp/StagingArea/AndroidManifest.xml’ is denied

I’m new to Android dev to have no idea what this means. Any ideas?

Couple of days ago I did a couple of successful builds on a Galaxy Tab 2 7.0. Now I’ve switched device to a Nexus 7; however it now won’t build on the old device either.

Getting a very similar error here. Are you using Perforce?

Error building Player: UnauthorizedAccessException: Access to the path “C:\UnityProjects\MyProject\Temp\StagingArea\res\values\strings.xml” is denied

Sorry to necro this post, but did you ever find a solution rbisso? I’m having the exact same issue on the same file using Perforce.

I’m having the same issue. Its extremely frustrating.

So I don’t know if this is a good idea, but it worked for me. I closed Unity, then deleted the “Temp” folder in my project. Then I opened unity and tried building again and it worked!

Should anyone else hit this, the issue is that when those files are copied, they retain their file attributes, including things like “read-only”. You can do one of two things.

Assuming use of Perforce, in Perforce edit your Workspace, and select the “Advanced” tab. Add “Allwrite” to leave your files writeable. That solves it for you personally.

If you write your own editor function to build your project, you can add a code section similar to this:

    if((System.Environment.OSVersion.Platform != System.PlatformID.Unix) && (System.Environment.OSVersion.Platform != System.PlatformID.MacOSX))
     {
       File.SetAttributes((Application.dataPath + "/PlugIns/Android/AndroidManifest.xml").Replace("/","\\"),FileAttributes.Normal);
     }
     else
     {
       File.SetAttributes(Application.dataPath + "/PlugIns/Android/AndroidManifest.xml",FileAttributes.Normal);
     }
     string AndroidResDirectory = Application.dataPath + "/PlugIns/Android/res";
     if((System.Environment.OSVersion.Platform != System.PlatformID.Unix) && (System.Environment.OSVersion.Platform != System.PlatformID.MacOSX))
     {
       AndroidResDirectory = AndroidResDirectory.Replace ("/", "\\");
     }
     foreach(string _stringsFile in Directory.GetFiles(AndroidResDirectory, "strings.xml", SearchOption.AllDirectories))
     {
       File.SetAttributes(_stringsFile, FileAttributes.Normal);
     }

This should solve it for everyone that uses the editor function to build the project.

1 Like