Skip to content

Commit a5ec2f1

Browse files
committed
Fix error detection on Windows. Update docs
1 parent 1dfffae commit a5ec2f1

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

Documentation/guides/messages/apt2264.md

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,29 @@ ms.date: 12/16/2022
99

1010
The tool `aapt2` is unable to resolve one of the files it was passed.
1111
This is generally caused by the path being longer than the Maximum Path
12-
length allowed on windows.
12+
length allowed on windows. Alternately it might be due to non-ASCII
13+
characters in the project name or the path to the project.
1314

1415
## Solution
1516

1617
The best way to avoid this is to ensure that your project is not located
17-
deep in the folder structure. For example if you create all of your
18-
projects in folders such as
18+
deep in the folder structure and does not contain non-ASCII characters.
19+
For example if you create all of your projects in folders such as
1920

20-
`C:\Users\shelly\Visual Studio\Android\MyProjects\Com.SomeReallyLongCompanyName.MyBrillantApplication\MyBrilliantApplicaiton.Android\`
21+
`C:\Users\shëlly\Visual Studio\Android\MyProjects\Com.SomeReallyLongCompanyName.MyBrillantApplication\MyBrilliantApplicaiton.Android\`
2122

2223
you may well encounter problems with not only `aapt2` but also Ahead of Time
23-
compilation. Keeping your project names and folder structures short and
24-
concise will help work around these issues. For example instead of the above
24+
compilation. Keeping your project names and folder structures short, concise and
25+
ASCII will help work around these issues. For example instead of the above
2526
you could use
2627

2728
`C:\Work\Android\MyBrilliantApp`
2829

2930
Which is much shorter and much less likely to encounter path issues.
3031

31-
However this is no always possible. Sometimes a project or a environment requires
32-
deep folder structures. In this case enabling long path support in Windows *might*
32+
However this is not always possible. Sometimes a project or a environment requires
33+
deep folder structures. For non-ASCII paths there is no work around.
34+
In the long path case, enabling long path support in Windows *might*
3335
be enough to get your project working. Details on how to do this can be found
3436
[here](https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later).
3537

src/Xamarin.Android.Build.Tasks/Properties/Resources.resx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,7 @@ Either change the value in the AndroidManifest.xml to match the $(SupportedOSPla
542542
{0} - The assembly name</comment>
543543
</data>
544544
<data name="APT2264" xml:space="preserve">
545-
<value>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.</value>
545+
<value>This is probably caused by the project having non-ASCII characters in it path or exceeding the Windows maximum path length limitation. See https://learn.microsoft.com/xamarin/android/errors-and-warnings/apt2264 for details.</value>
546546
<comment>The following are literal names and should not be translated:</comment>
547547
</data>
548548
<data name="XA3001" xml:space="preserve">

src/Xamarin.Android.Build.Tasks/Tasks/Aapt2.cs

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,22 +138,8 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me
138138
LogCodedError ("APT0001", Properties.Resources.APT0001, message.Substring ("unknown option '".Length).TrimEnd ('.', '\''));
139139
return false;
140140
}
141-
if (message.Contains ("in APK") && message.Contains ("is compressed.")) {
142-
LogMessage (singleLine, messageImportance);
141+
if (LogNotesOrWarnings (message, singleLine, messageImportance))
143142
return true;
144-
}
145-
if (message.Contains ("fakeLogOpen")) {
146-
LogMessage (singleLine, messageImportance);
147-
return true;
148-
}
149-
if (message.Contains ("note:")) {
150-
LogMessage (singleLine, messageImportance);
151-
return true;
152-
}
153-
if (message.Contains ("warn:")) {
154-
LogCodedWarning (GetErrorCode (singleLine), singleLine);
155-
return true;
156-
}
157143
if (level.Contains ("note")) {
158144
LogMessage (message, messageImportance);
159145
return true;
@@ -199,6 +185,8 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me
199185

200186
if (!apptResult) {
201187
var message = string.Format ("{0} \"{1}\".", singleLine.Trim (), singleLine.Substring (singleLine.LastIndexOfAny (new char [] { '\\', '/' }) + 1));
188+
if (LogNotesOrWarnings (message, singleLine, messageImportance))
189+
return true;
202190
var errorCode = GetErrorCode (message);
203191
LogCodedError (errorCode, AddAdditionalErrorText (errorCode, message), ToolName);
204192
} else {
@@ -207,6 +195,27 @@ protected bool LogAapt2EventsFromOutput (string singleLine, MessageImportance me
207195
return true;
208196
}
209197

198+
bool LogNotesOrWarnings (string message, string singleLine, MessageImportance messageImportance)
199+
{
200+
if (message.Contains ("in APK") && message.Contains ("is compressed.")) {
201+
LogMessage (singleLine, messageImportance);
202+
return true;
203+
}
204+
if (message.Contains ("fakeLogOpen")) {
205+
LogMessage (singleLine, messageImportance);
206+
return true;
207+
}
208+
if (message.Contains ("note:")) {
209+
LogMessage (singleLine, messageImportance);
210+
return true;
211+
}
212+
if (message.Contains ("warn:")) {
213+
LogCodedWarning (GetErrorCode (singleLine), singleLine);
214+
return true;
215+
}
216+
return false;
217+
}
218+
210219
static string AddAdditionalErrorText (string errorCode, string message)
211220
{
212221
var sb = new StringBuilder ();
@@ -226,7 +235,6 @@ static string GetErrorCode (string message)
226235
if (message.IndexOf (tuple.Item2, StringComparison.OrdinalIgnoreCase) >= 0)
227236
return tuple.Item1;
228237

229-
Console.WriteLine ($"DEBUG could not match '${message}'");
230238
return "APT2000";
231239
}
232240

@@ -494,7 +502,7 @@ static string GetErrorCode (string message)
494502
Tuple.Create ("APT2261", "file failed to compile"),
495503
Tuple.Create ("APT2262", "unexpected element <activity> found in <manifest>"),
496504
Tuple.Create ("APT2263", "found in <manifest>"), // unexpected element <xxxxx> found in <manifest>
497-
Tuple.Create ("APT2264", "The system cannot find the file specified. (2).") // Windows Long Path error from aapt2
505+
Tuple.Create ("APT2264", "The system cannot find the file specified. (2)") // non-ASCII or Windows Long Path error from aapt2
498506
};
499507
}
500508
}

0 commit comments

Comments
 (0)