Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice
  4. Dismiss Notice

Android build: Unauthorized access exception

Discussion in 'Android' started by ecc83, Jun 17, 2013.

  1. ecc83

    ecc83

    Joined:
    Nov 23, 2012
    Posts:
    32
    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.
     
  2. rbisso

    rbisso

    Joined:
    Jul 13, 2011
    Posts:
    29
    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
     
  3. tim_h

    tim_h

    Joined:
    Feb 13, 2014
    Posts:
    10
    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.
     
  4. xevierh

    xevierh

    Joined:
    Dec 18, 2013
    Posts:
    1
    I'm having the same issue. Its extremely frustrating.
     
  5. Jus10

    Jus10

    Joined:
    Oct 24, 2014
    Posts:
    1
    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!
     
  6. rihdus

    rihdus

    Joined:
    Jul 13, 2012
    Posts:
    10
    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:
    Code (csharp):
    1.  
    2.     if((System.Environment.OSVersion.Platform != System.PlatformID.Unix) && (System.Environment.OSVersion.Platform != System.PlatformID.MacOSX))
    3.      {
    4.        File.SetAttributes((Application.dataPath + "/PlugIns/Android/AndroidManifest.xml").Replace("/","\\"),FileAttributes.Normal);
    5.      }
    6.      else
    7.      {
    8.        File.SetAttributes(Application.dataPath + "/PlugIns/Android/AndroidManifest.xml",FileAttributes.Normal);
    9.      }
    10.      string AndroidResDirectory = Application.dataPath + "/PlugIns/Android/res";
    11.      if((System.Environment.OSVersion.Platform != System.PlatformID.Unix) && (System.Environment.OSVersion.Platform != System.PlatformID.MacOSX))
    12.      {
    13.        AndroidResDirectory = AndroidResDirectory.Replace ("/", "\\");
    14.      }
    15.      foreach(string _stringsFile in Directory.GetFiles(AndroidResDirectory, "strings.xml", SearchOption.AllDirectories))
    16.      {
    17.        File.SetAttributes(_stringsFile, FileAttributes.Normal);
    18.      }
    19.  
    This should solve it for everyone that uses the editor function to build the project.
     
    zwcloud likes this.