可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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):
My build.gradle(app) file (this is not the edited file, I deleted new lines of code and still no luck/solution.):
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.
回答1:
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.
回答2:
You could also try changing your build directory for your project since that is where most of the path issues will arise. In your root build.gradle file
allprojects {
buildDir = "C:/tmp/${rootProject.name}/${project.name}"
repositories {
...
}
}
Android Studio will pick up on the change and still show your new build location in the Project view. It's a lot easier than moving your entire project.
EDIT
While Windows 10 Insider Preview now offers the ability for allowing for longer file path limits these limits currently are only actually accessible to apps which have specifically enabled support for longer file paths.
At the current time, it appears that these applications with the extended path enabled seem to be only apps that are installed via the Windows Store.
At the current time, Gradle does not and potentially cannot have this option enabled to utilize the enhanced NTFS file path length.
回答3:
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
回答4:
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.
回答5:
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
回答6:
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())}"
}
回答7:
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
回答8:
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
回答9:
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
回答10:
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
回答11:
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
回答12:
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.
回答13:
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.