Error: File path too long on windows, keep below 2

2019-01-06 09:26发布

So, I made some changes to my build.gradle(app) file and android studio gives me this error (open the image in new tab for better viewing): Error description from Logcat

My build.gradle(app) file (this is not the edited file, I deleted new lines of code and still no luck/solution.): Build.gradle

Everything was quite working well until I made some changes in the build.gradle(app) file, but then I deleted those new lines of codes and android studio is still keep giving me the error. The error relates to the compile 'com.google.android.gms:play-services:8.3.0'. I have tried deleting/renaming those png images inside the stated folder,but then when I rebuild the project, the png images are automatically downloaded. My build.gradle(project) file contains classpath 'com.android.tools.build:gradle:1.5.0'. I want to know what causes this error, and how to fix it? Many thanks.

13条回答
beautiful°
2楼-- · 2019-01-06 09:48

For Windows users:

You might be tempted to create a network share to the project root folder and then map to it. This technique will shorten the overall path length but will cause problems for Android Studio due to the difficulty in detecting modified files. A better solution is to use the windows subst command. Here is an example script to circumvent the problem. Tweak names as necessary and modify to point to your project and install directories.

File: launchAS.cmd

subst P: "C:\private\java42\ide\42g\workspaces\AndroidStudioProjects"
cd "C:\private\java42\programs\android-studio-base\bin"
start studio64.exe

The above commands will create a P: drive and map it to the project root folder. This will reduce the overall path length to project files and might give you some relief for the too long path name problem. Use P:\ as you would have used the long root name when opening projects.

To remove the mapping use command: subst P: /d

查看更多
ゆ 、 Hurt°
3楼-- · 2019-01-06 09:49

As a very solid alternative to actually moving the project I'd suggest using a hard link. The syntax of that would be like this

mklink /J C:\AndroidProjects\ProjectName C:\MyVeryVeryVeryVery…VeryVeryVeryLongPath\ProjectName

Now you can work on your project in C:\AndroidProjects\ProjectName, and have the changes right where your project is supposed to be.

查看更多
放我归山
4楼-- · 2019-01-06 09:50

Have look at this http://feelzdroid.com/2016/01/android-studio-error-file-path-too-long-windows.html. Solution is too simple keep path of folder less then 240 characters.

Make sure you will have less then 240 charters in the path

查看更多
Explosion°爆炸
5楼-- · 2019-01-06 09:51

I just ran into the same issue. I don't know a fix for your exact problem, but I found a work around; I see your project has a deep file path hierarchy. Why not just move your project up from a lower level?

Ex: C:\Projects\YourProject

That fixed the problem for me.

查看更多
爷的心禁止访问
6楼-- · 2019-01-06 09:52

I found this issue when I have two repeated folder in same like,

E:\project-one\project-one

and when it has a large length of folder name like,

E:\project-one-with-very-big-name

To avoid this problem make a folder of project simple and short.

查看更多
再贱就再见
7楼-- · 2019-01-06 09:53

You can use NTFS junction point to create shorter path to your project. To read more about Junctions read this : Hard Links and Junctions

A junction (also called a soft link) differs from a hard link in that the storage objects it references are separate directories, and a junction can link directories located on different local volumes on the same computer. Otherwise, junctions operate identically to hard links

查看更多
登录 后发表回答