-
Notifications
You must be signed in to change notification settings - Fork 538
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle aapt2
error "The system cannot find the file specified." slightly better
#7644
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
--- | ||
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 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 | ||
with solve these issues. Adding a file with the following contents will create the `obj` | ||
directory in a different location of your choosing. | ||
|
||
``` | ||
<Project> | ||
<PropertyGroup> | ||
<BaseIntermediateOutputPath Condition=" '$(OS)' == 'Windows_NT' ">C:\Intermediate\$(ProjectName)</BaseIntermediateOutputPath> | ||
<BaseIntermediateOutputPath Condition=" '$(OS)' != 'Windows_NT' ">/tmp/Intermediate/$(ProjectName)</BaseIntermediateOutputPath> | ||
</PropertyGroup> | ||
</Project | ||
``` | ||
|
||
Using this technique will reduce the lengths of the paths sent to the various tools like `aapt2`. | ||
Note this is generally only a Windows issue. So there is no need to override the `$(BaseIntermediateOutputPath)` | ||
on Mac or Linux based environments. However you might want to override everywhere to be consistent. |
9 changes: 9 additions & 0 deletions
9
src/Xamarin.Android.Build.Tasks/Properties/Resources.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we suggest enabling long paths as the 1st solution?
https://learn.microsoft.com/windows/win32/fileio/maximum-file-path-limitation?tabs=registry#enable-long-paths-in-windows-10-version-1607-and-later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As per the docs, two things must be done: the registry must be updated to set
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\LongPathsEnabled
-- and I wonder if that could/would break anything -- and secondly:We do not currently ship an
aapt2.exe.config
manifest file.Additionally, it may be moot; the next section in docs states:
Are these used?
Odd is
GetFileAttributesA
, which presumably hasMAX_PATH
limits, butGetFileAttributesW
is also used, so when isGetFileAttributesA
used vs.GetFileAttributesW
? ¯\(ツ)/¯.GetModuleFileNameA
is also concerning, so it would not surprise me ifaapt2.exe
didn't work with long filenames even if we set the registry entry and provided an appropriateaapt2.exe.config
manifest.This requires testing, but I suspect that there's no point in suggesting the enabling of long paths, as
aapt2
won't work with them.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aapt2
uses this function to convert UTF-8 file names to Windows UnicodeThe android base library also has wrappers around the standard C I/O functions which add support for UTF-8 strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This strongly implies that if we provide an appropriate
aapt2.exe.config
, we can get long file name support if/when the registry setting is enabled.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So shall I add the
aapt2.exe.config
to this PR or do a new one for that specific file?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should just check if you need it? My memory in the past, I just changed the registry key and everything worked.
But I don't remember if I was hitting an issue with
aapt2
or a .NET process (which would probably opt into long paths).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dellis1972: if this PR were "green" and otherwise ready to merge, I think
aapt2.exe.config
could be done as a separate PR. Given that this PR isn't green and ready to merge, might as well test locally and see if that works?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting, VS 2022 Preview wont even open a project/solution if the full path is greater than 260 characters even with LongPath enabled... you get a horrible dialog box.
Building with slightly fewer that 260 characters I get this build error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might have to test an "almost long path", where only aapt2 would get long path errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did some more testing and it seems that
aapt2
was able to switch to log paths with only the registry setting change (not aapt2.exe.config file).I know this because the diagnostic output was putting the
\\?\
stuff at the start of the filenames. So I don't think we need the config file. I will update the docs to mention the registry change though.