From 9cb17e46a294a9d8c81a214ae575cd8ebb487f71 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 16 Dec 2022 14:04:30 +0000 Subject: [PATCH 1/5] Test this theory out --- Documentation/guides/messages/README.md | 1 + .../Properties/Resources.Designer.cs | 9 ++++++++ .../Properties/Resources.resx | 4 ++++ .../Tasks/Aapt2.cs | 23 ++++++++++++++++--- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Documentation/guides/messages/README.md b/Documentation/guides/messages/README.md index c31c84e89dc..c32d917a755 100644 --- a/Documentation/guides/messages/README.md +++ b/Documentation/guides/messages/README.md @@ -30,6 +30,7 @@ ms.date: 01/24/2020 + APT0002: Invalid file name: It must contain only \[^a-zA-Z0-9_.-\]+. + APT0003: Invalid file name: It must contain only \[^a-zA-Z0-9_.\]+. + APT0004: Invalid file name: It must start with either A-Z or a-z or an underscore. ++ [APT2264](apt2264.md): The system cannot find the file specified. (2). ## JAVAxxxx: Java Tool diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs index c87254b93ce..a086eaa35f3 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs @@ -800,6 +800,15 @@ public static string XA2008 { } } + /// + /// Looks up a localized string similar to This is probably caused by the project exceeding the Max Path length. Please move your entire project closer to the Root of the drive.. + /// + public static string APT2264 { + get { + return ResourceManager.GetString("APT2264", resourceCulture); + } + } + /// /// Looks up a localized string similar to Could not AOT the assembly: {0}. /// diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index c36b272704b..36934adc436 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -530,6 +530,10 @@ Please change the value to an assembly-qualifed type name which inherits from '{ The following are literal names and should not be translated: Java.Interop.DoNotPackageAttribute {0} - The assembly name + + This is probably caused by the project exceeding the Max Path length. See https://learn.microsoft.com/en-us/xamarin/android/errors-and-warnings/apt2264 for details. + The following are literal names and should not be translated: + Could not AOT the assembly: {0} The abbreviation "AOT" should not be translated. diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs index 961005e362a..c7f32483ef9 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs @@ -188,23 +188,39 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me message = message.Substring ("error: ".Length); if (level.Contains ("error") || (line != 0 && !string.IsNullOrEmpty (file))) { + var errorCode = GetErrorCode (message); if (manifestError) - LogCodedError (GetErrorCode (message), string.Format (Xamarin.Android.Tasks.Properties.Resources.AAPTManifestError, message.TrimEnd('.')), AndroidManifestFile.ItemSpec, 0); + LogCodedError (errorCode, string.Format (Xamarin.Android.Tasks.Properties.Resources.AAPTManifestError, message.TrimEnd('.')), AndroidManifestFile.ItemSpec, 0); else - LogCodedError (GetErrorCode (message), message, file, line); + LogCodedError (errorCode, AddAdditionalErrorText (errorCode, message), file, line); return true; } } if (!apptResult) { var message = string.Format ("{0} \"{1}\".", singleLine.Trim (), singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1)); - LogCodedError (GetErrorCode (message), message, ToolName); + var errorCode = GetErrorCode (message); + LogCodedError (errorCode, AddAdditionalErrorText (errorCode, message), ToolName); } else { LogCodedWarning (GetErrorCode (singleLine), singleLine); } return true; } + static string AddAdditionalErrorText (string errorCode, string message) + { + var sb = new StringBuilder (); + sb.AppendLine (message); + switch (errorCode) + { + case "APT2264": + sb.AppendLine (Xamarin.Android.Tasks.Properties.Resources.APT2264); + break; + default: + } + return sb; + } + static string GetErrorCode (string message) { foreach (var tuple in error_codes) @@ -478,6 +494,7 @@ static string GetErrorCode (string message) Tuple.Create ("APT2261", "file failed to compile"), Tuple.Create ("APT2262", "unexpected element found in "), Tuple.Create ("APT2263", "found in "), // unexpected element found in + Tuple.Create ("APT2264", "The system cannot find the file specified. (2).") // Windows Long Path error from aapt2 }; } } From 3871b270ff4ecdd64d30f01d8b2bac2cdaeab027 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Fri, 16 Dec 2022 14:29:17 +0000 Subject: [PATCH 2/5] fix bug --- src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs index c7f32483ef9..193a72e630f 100644 --- a/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs +++ b/src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs @@ -216,9 +216,8 @@ static string AddAdditionalErrorText (string errorCode, string message) case "APT2264": sb.AppendLine (Xamarin.Android.Tasks.Properties.Resources.APT2264); break; - default: } - return sb; + return sb.ToString (); } static string GetErrorCode (string message) From 3a9164877bfbddb44d4ee72ea54ab391b0206af3 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Tue, 3 Jan 2023 09:45:44 +0000 Subject: [PATCH 3/5] Add Docs --- Documentation/guides/messages/apt2264.md | 53 ++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 Documentation/guides/messages/apt2264.md diff --git a/Documentation/guides/messages/apt2264.md b/Documentation/guides/messages/apt2264.md new file mode 100644 index 00000000000..16665a3917d --- /dev/null +++ b/Documentation/guides/messages/apt2264.md @@ -0,0 +1,53 @@ +--- +title: Xamarin.Android error APT2264 +description: APT2264 error code +ms.date: 12/16/2022 +--- +# Xamarin.Android error APT2264 + +## Issue + +The tool `aapt2` is unable to resolve one of the files it was passed. +This is generally caused by the path being longer than the Maximum Path +length allowed on windows. + +## Solution + +The best way to avoid this is to ensure that your project is not located +deep in the folder structure. For example if you create all of your +projects in folders such as + +`C:\Users\shelly\Visual Studio\Android\MyProjects\Com.SomeReallyLongCompanyName.MyBrillantApplication\MyBrilliantApplicaiton.Android\` + +you may well encounter problems with not only `aapt2` but also Ahead of Time +compilation. Keeping your project names and folder structures short and +concise will help work around these issues. For example instead of the above +you could use + +`C:\Work\Android\MyBrilliantApp` + +Which is much shorter and much less likely to encounter path issues. + +However this is no always possible. Sometimes a project or a environment requires +deep folder structures. In this case changing the location of the `$(BaseIntermediateOutputPath)` +can solve these problems. In order for this to work the setting MUST be changed +before ANY build or restore occurs. To do this you can make use of the MSBuild +`Directory.Build.props` support. + +Creating a `Directory.Build.props` file in your solution or project directory which +redefines the `$(BaseIntermediateOutputPath)` to somewhere nearer the root of the drive +with solve these issues. Adding a file with the following contents will create the `obj` +directory in a different location of your choosing. + +``` + + + C:\Intermediate\$(ProjectName) + /tmp/Intermediate/$(ProjectName) + + Date: Thu, 19 Jan 2023 14:35:26 +0000 Subject: [PATCH 4/5] Update docs --- Documentation/guides/messages/apt2264.md | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Documentation/guides/messages/apt2264.md b/Documentation/guides/messages/apt2264.md index 16665a3917d..d058a29a74f 100644 --- a/Documentation/guides/messages/apt2264.md +++ b/Documentation/guides/messages/apt2264.md @@ -29,10 +29,15 @@ you could use Which is much shorter and much less likely to encounter path issues. However this is no always possible. Sometimes a project or a environment requires -deep folder structures. In this case changing the location of the `$(BaseIntermediateOutputPath)` -can solve these problems. In order for this to work the setting MUST be changed -before ANY build or restore occurs. To do this you can make use of the MSBuild -`Directory.Build.props` support. +deep folder structures. In this case enabling long path support in Windows *might* +be enough to get your project working. Details on how to do this can be found +[here](https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later). + + +If long path support does not work changing the location of the +`$(BaseIntermediateOutputPath)` can help solve these problems. In order for this +to work the setting MUST be changed before ANY build or restore occurs. To do this +you can make use of the MSBuild `Directory.Build.props` support. Creating a `Directory.Build.props` file in your solution or project directory which redefines the `$(BaseIntermediateOutputPath)` to somewhere nearer the root of the drive From 939a7418d404a5fa0a3600f9e65c3877b645dbd9 Mon Sep 17 00:00:00 2001 From: Dean Ellis Date: Thu, 19 Jan 2023 14:47:55 +0000 Subject: [PATCH 5/5] Fix the error message --- src/Xamarin.Android.Build.Tasks/Properties/Resources.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx index 36934adc436..f78a40c1314 100644 --- a/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx +++ b/src/Xamarin.Android.Build.Tasks/Properties/Resources.resx @@ -531,7 +531,7 @@ Please change the value to an assembly-qualifed type name which inherits from '{ {0} - The assembly name - This is probably caused by the project exceeding the Max Path length. See https://learn.microsoft.com/en-us/xamarin/android/errors-and-warnings/apt2264 for details. + This is probably caused by the project exceeding the Windows maximum path length limitation. See https://learn.microsoft.com/xamarin/android/errors-and-warnings/apt2264 for details. The following are literal names and should not be translated: