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条回答
Ridiculous、
2楼-- · 2019-01-06 09:32

Cause of problem : 'C:\users...\commom_google_signin_btn_text_dark_normal.9.png' icon path length is greater than 240 character which exceeds Maximum File Path Length Limitation of Windows OS.

Solution is : Move your project into top directory like 'C:\your_project' or reduce length of your project name.

Here is windows path limit chart enter image description here

查看更多
闹够了就滚
3楼-- · 2019-01-06 09:40

I agree with Vladimir Dimov answer. You must choose the short path for your project as it is mentioned that the file path should be below 240 characters on Windows. This link helps me out : http://www.feelzdroid.com/2016/01/android-studio-error-file-path-too-long-windows.html

查看更多
别忘想泡老子
4楼-- · 2019-01-06 09:41

As an addition on lodock's answer, you can use a hash on the project path if you have lots of projects with the same name:

import java.security.MessageDigest

def hashString(String s){
    MessageDigest.getInstance("SHA1").digest(s.bytes).encodeHex().toString()
}

allprojects {
    buildDir = "C:/AB/${hashString(projectDir.getAbsolutePath())}"
}
查看更多
时光不老,我们不散
5楼-- · 2019-01-06 09:44

I was facing the same issue , my project is in C drive and it is in deeper path location, What i did I just moved my project to other lower deep path location and it works, you just change the project location and project should not be in deep location hierarchy.

查看更多
来,给爷笑一个
6楼-- · 2019-01-06 09:46

You Should Have To Keep Your Project Directory As Less Deep As Possible For Example:- D:/AndroidWorkSpace/ProjectName

Because Android Studio Support Only 240 Character length of Project Path

Thanks

查看更多
Anthone
7楼-- · 2019-01-06 09:48

Shortening project paths is really a bit of a hack, Ivan Neeson's response seems the way forward.

If you are lucky enough to be using Android Studio then you will see a useful error message about file length. If however you hit the same issue doing a command line ionic build all you will see if some kind of crunch error for a png file and it's not so obvious.

The real issue is Google Play Services having such extravagant filenames such as common_google_signin_btn_text_light_normal_background.9.png which is simply not Windows friendly. Dump that inside an Android build and the path explodes outside our control to platforms\android\build\intermediates\exploded-aar\com.google.android.gms\play-services-base\10.2.1\res\drawable-xhdpi-v4\common_google_signin_btn_text_light_normal_background.9.png

查看更多
登录 后发表回答