Simple builds for Android keep failing with unauthorized exceptions.
I have been tearing my hair out trying to get Unity to do a simple build of a game for Android - always getting the same error (with any game) - see below.
UnauthorizedAccessException: Access to the path "...mygame\Temp\StagingArea\res\values\strings.xml" is denied. System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.IO/FileStream.cs:320) System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share) (wrapper remoting-invoke-with-check) System.IO.FileStream:.ctor (string,System.IO.FileMode,System.IO.FileAccess,System.IO.FileShare) System.Xml.XmlTextWriter..ctor (System.String filename, System.Text.Encoding encoding) UnityEditor.AndroidXmlDocument.SaveAs (System.String path) UnityEditor.AndroidXmlDocument.Save () UnityEditor.Android.PostProcessor.Tasks.PrepareAPKResources.PatchStringsXml () UnityEditor.Android.PostProcessor.Tasks.PrepareAPKResources.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (BuildPostProcessArgs args) UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTargetGroup targetGroup, BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.BuildReporting.BuildReport report) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:271) UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
This error has been noted before in a previous posting : https://forum.unity.com/threads/access-to-the-path-c-temp-staging_area-res-values-strings-xml-is-denied.433124/ but without a definite analysis of the problem and work around solution.
Versions: Android SDK 3.1.3, Java JDK jdk1.8.0_171, Unity 2017.2.0f3
Even deleting the Temp and Library directories and rebuilding does not cure the problem.
The file in question, strings.xml is read-only which explains the error message. The question is what template was used by Unity to create that strings.xml file. The template file must be read-only and I need to unset the readonly attribute.
But where is this template? Although the Unity source code for Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs is available for scrutiny I cannot find source code for Unity Android AndroidBuild etc.
Any help at all would be appreciated?
Nigel & Jules
Answer by juleslhoward · Jul 15, 2018 at 11:04 AM
The problem seems to have been caused by the Unity\Editor\Data directory being set to Hidden when Unity 2017.2.0f3 was installed on our Windows 7 desktop. Don't ask me how or why! Un-setting the hidden attribute for the directory and all the contents seems to have solved the problem and allowed the Android build to complete successfully.
Your answer
Follow this Question
Related Questions
Blank Project show error while create Android Build 0 Answers
Invalid Android SDK directory? 1 Answer
Game crashes on mobile 0 Answers
Can't Build Android APK 1 Answer