resolve xamarin android "path too long" without relocation
Asked Answered
A

4

8

I have recently started getting the error ResolveLibraryProjectImports: PathTooLongException on my xamarin android project within xamarin.forms. When I look up online all solutions say to relocate the project. Is there any way to change the project properties or a way to remap that can help me avoid relocating the entire project?

Update:

Due the the bounty and since the question has come up below, here is why I am looking for an alternate solution to relocating:

Directory hierarchies are there for a reason. If not everyone would have the whole bunch of folders the root. They are designed to allow us to organize everything. Same is my case. I have organized all folders based cloud, codes, frameworks etc. Of all the frameworks I have worked with, I have never had relocate a project because of an internal requirement of the project. So, I do not see a reason I need to move a project out of all these folders (which also means out of cloud) and throw them in some location apart from the rest of the projects, just because the project asks for it.

Amends answered 3/11, 2017 at 5:5 Comment(2)
What is hindering you from relocating the project? Which .NET Framework do you target? (Saw this comment in the MSDN doc just now: Starting with apps running under the .NET Framework 4.6.2, the .NET Framework supports long paths in excess of 260 (or MAX_PATH) characters.)Unequal
@Marimba just saw your comment. I am using xamarin forms that targets 4.5 .NET Frameworks. I was unable to update this framework. More over this isn't a .NET issue but a java issue within the android framework. I have faced the same issue when directly creating android projects too. As of what is hindering, I am updating the questionAmends
E
4

I faced the same Issue before, here is what I have found :

Windows has a Maximum Path Length Limitation. You could see it in Windows Naming Files, Paths, and Namespaces :

Maximum Path Length Limitation In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters. A local path is structured in the following order: drive letter, colon, backslash, name components separated by backslashes, and a terminating null character. For example, the maximum path on drive D is "D:\some 256-character path string" where "" represents the invisible terminating null character for the current system codepage. (The characters < > are used here for visual clarity and cannot be part of a valid path string.) This is the reason why you have the issue.

You could shorten the directory path to your project to solve this problem, another solution is use the long path tool. But as PierceBoggan said :

the easiest way to avoid this issue is to move your source to the C:/ drive (or another location with fewer characters in the path).


Update :

The issue was fixed in Xamarin.Android 8.0.2.1, and this version is included in the Visual Studio 2017 version 15.4.2 release. You could read this document :

https://developer.xamarin.com/releases/android/xamarin.android_8/xamarin.android_8.0/#Issues_Fixed

Erda answered 10/11, 2017 at 16:2 Comment(9)
other's have tried the long path tool options and ran into issues. even if possible. Even if it is used, how can it be implemented into the project?Amends
@NevilleNazerane, actually, the best solution is move your project to a shorter path.Erda
well i know that and is also mentioned in my question. my question is what is the alternate. I have also mentioned why moving the project a sensible solution in many casesAmends
@NevilleNazerane, sorry for any inconvenience, but I cant find any other solution that could solve this problem.Erda
yeah i get it. others couldn't either. i was just adding comments to keep a record of why i can't mark this as the answer. i do not mean to abuse you by saying "not a sensible solution". A project shouldn't make you have to do something like thisAmends
@NevilleNazerane, totally agree with you.Erda
@NevilleNazerane, I have update my answer, please check it.Erda
the release notes don't exactly talk about this issue as far as i can seeAmends
@NevilleNazerane, 30147 : Path is too longErda
A
3

Literally every new Xamarin Forms project that I try and build hits the MAXPATH error on the Android project the first time (because my default Projects Github folder path is already long).

I have a simple and routine fix that for me works for me 100% of the time because the culprit in my case is the intermediate or [obj] folder.

Try this: Open the .csproj file in notepad. Make sure it's the .csproj for the Android project. Under the first <PropertyGroup> tag add this element:

`<BaseIntermediateOutputPath>C:/Intermediate/Android/YourProjectName</BaseIntermediateOutputPath>` 

Now just reload the project and try building again. Hope this helps!

Acth answered 16/4, 2020 at 20:8 Comment(1)
Awesome! This ought to be the accepted answer. Simple and effective.Seng
V
2

I faced this issue too. Updating VS 2017 to 15.4.0 fixed it for me. Moving it closer to C:\ didn't change anything.

Venezuela answered 15/11, 2017 at 7:38 Comment(1)
well I faced this issue in a newer version than 15.4.0. I don't really think the version fixed the issue. I too noticed certain ways when I open the issue comes and goes too. I can't really pin down the exact cause of the issue.Amends
S
2

I had this problem even when moving my project to root of drive. However after updating Visual Studio to the newest version(15.7.0) the option to change archive output directory has been added to IDE:

Tools --> Options--> Android Settings : Archives Location

enter image description here

By setting this location to a directory as close to drive root as possible(such as D:\Archives), this error will go away.

Serieswound answered 8/5, 2018 at 11:15 Comment(1)
Also works for iOS. Just select iOS Settings instead.Rowdyism

© 2022 - 2024 — McMap. All rights reserved.