Error: File path too long on windows, keep below 240 characters - android

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 code 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.

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.

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.

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

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.

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

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())}"
}

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

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

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.

You Should Have To Keep Your Project Directory As Less Deep As Possible
For Example:-
D:/AndroidWorkSpace/ProjectName
Because Gradle Support Only 240 Character length of Project Path
Thanks

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

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

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.

I had a different experience with this problem. First I has this error but then i noticed that my previous projects in the same directory were opening. This is the path:
C:\Users\koralis\Documents\extraction\Ex_Files_Android_App_Dev_LDS_Upd\Exercise Files\Ch01\01_06\ImageAssets
Surprisingly, I updated that gradle version to
'com.android.tools.build:gradle:3.2.1' from 'com.android.tools.build:gradle:2.0.0'
This solved my problem.

Related

Gradle Daemon Initialization script failed unexpected token ' in username

I downloaded the latest version of Android studio and created a new project, but it seems that I can't get it to work since the Gradle Daemon is failing because my windows user has a comma ' . My username also has a space, but I guess that I shall see if I will get another error when I reach there.
Any settings that I can do to bypass this problem, without changing my user name?
You could try various hacky things like setting your GRADLE_USER_HOME and TEMP environment variables to folders outside your user space (e.g. C:\gradle & C:\temp).
However, you're going to be fighting against Gradle / Android / the entire build process now and forever! I'd really really recommend instead using a name without special characters. If this isn't possible, perhaps a new user with a simple name would be a quick fix.
After some searching, I had an idea and I found a possible solution:
The solution is a mix of these 2 questions:
Set gradle temporary directory to SSD
Android Studio missing essential plugin org.jetbrains.android
1. Change Gradle temp files to another directory
Create a new folder ex: D:\some\dir\
Go to System Properties and edit the Envitonment Variables.
Add GRADLE_OPTS with -Djava.io.tmpdir=D:\some\dir\
Add GRADLE_USER_HOME with D:\some\dir\
2. Remove disabled_plugins.txt file
Go to the following path and delete the file:
C:\Users\YourUserName\AppData\Roaming\Google\AndroidStudioVersion\disabled_plugins.txt
3. Re-create the project

Unity3D Command line Build not accessing libraries and updating Android Manifest

I have a unity project with multiple android plugins.
The plugins are placed in the recommended folders /Assets/Plugins/Android/NameOfPlugin and each have their own AndroidManifest.xml and .project file.
I also have an AndroidManifest.xml in /Assets/Plugins/Android
When building out a .apk from any of the dev machines in studio, the AndroidManifest is correctly compiled into a single .xml file containing all required activities.
However, when building on a Mac Mini via commandline this does not happen. The AndroidManifest.xml is missing required code and the app doesn't work.
I have done fresh installs of everything, tried different configurations, loads of things but to no avail. Anyone have any ideas as to what might be going wrong?
One of Dan's colleagues here, and after doing a straight up text diff on the two "Editor.log" files of Unity's editor, there was one glaring line that was missing from the broken builder,
DisplayProgressbar: Android Library Support
Googling that lead me to http://answers.unity3d.com/questions/792979/android-library-support-build-issue.html who had already discovered the answer, which was damn near exactly the same as what we had suffered,
It appears having a "." in the name of a directory on the build path results in failure of the android-libraries to be correctly found and added to the StagingArea.
Moving our repository on the Autobuilder from ~/.jenkins/workspace/game_project to ~/game_project fixed the issue.
We've just done the same ourselves, and it's solved the issue.

Android studio suddenly cannot resolve symbol R

I was having a project open in Android studio. It was generated by the wizard and working fine.
I did some small changes to activity_main.xml and when I changed back to MainActivity.java i get the error in several places that it cannot resolve R. I might have done something to cause this. But I´m not sure what since it appered when I edited the xml.
Does anyone know what might be the solution to this?
I can find the R.java in r/release/packege/com/ and it looks fine.
Most of the time it is due to a bad XML file. XML files can be layout files, value files, or the Manifest file. Please check your xml files and try to rebuild the project. Sometimes cleaning the project and rebuilding it also works.
In addition, make sure you do not have a drawable with an invalid name. I had a drawable with a numeric filename and that didn't sit well with Android so it failed to compile R.java.
Downgrade Your Gradle Plugin Version
No amount of cleaning, rebuilding and restarting would do the trick for me.
The only thing that did the trick was downgrade our Gradle version from 3.4.0-alpha02 to 3.2.1.
So, instead of:
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0-alpha02'
}
We used:
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
}
After making that change and then doing a Gradle sync, everything worked.
Not sure if it's related to the alpha release or to that version or if changing your Gradle version at all just forces a refresh that otherwise cannot be done with the other commands, but there ya go.
Make sure in your AndroidManifest.xml the package name is correct. That fixed the problem for me when my R.whatever was marked red!
Try to clean the project by doing the following:
If you are using Windows, open CMD, cd to your project directory and run gradlew clean.
I just had this problem and the reason was that after editing the layout android studio automatically added an import to the source files:
import android.R
Of course the main R class has not all the symbols in your layouts, which made everything a red mess.
Removing that line solved for me.
EDIT:
Seems like eclipse had the same problem early on.
I sometimes get this after updating Android Studio. Not always straight away but after a while (perhaps after a restart of the program).
Here is what has worked for me: Tools - Android - Sync project with Gradle files.
For some reason just clicking the "Sync now" link that shows up after changing the build.gradle file has not done any change for me. Even though the messages says approximately the same thing.
I had the same problem because in my strings.xml I forgot to escape a apostrophe. Use " \' " never " ' " in xml file!
I had that same problem crop up, too (most recently while I was at lunch--came back and WTF?). And since this was a simple Hello, World program, there wasn't many places these errors could hide. The XML files looked fine--I hadn't even touched the manifest. A clean did nothing.
So I commented out a section of my layout.xml to try to narrow down the problem. Sure enough, the errors went away.
And then I simply UNcommented out exactly what I had commented...and everything was hunky-dory. Strange! Perhaps there was some lingering issues that needed to be touched in order to cause a rebuild of the layout file. You'd think basic stuff like that wouldn't happen these days, but they do.
One more thing! It's possible that something may happen to Java as well. It's very hard to know the status of the Java run-time environment; just easier to start again. So here's one more thing to try: restart your computer, restart Android Studio, AND THEN Invalidate Caches and Restart. Yep, the whole-hog.
When all else fails restarting android sometimes helps. During the start files are loaded afresh and this enables detection of the R
This problem occurs when you rename the package name.
After renaming the package name, you must change the older package
name to a newer one.
For me it solved the problem once I changed that.
After that, you might get errors in xml files, that you have to change
the package name there also.
That's it.
I just had the R problem and after a few hours found that the problem was my regional spelling as used in one of my xml files. The problem word was behaviour, which is spelled behavior by Americans.
I am Australian and we are taught ye olde English way of spelling certain words and so I looked past it a number of times before the penny dropped.
Its a small thing, but it can easily sneak up and bite you on the nether regions and is hard to spot and can waste a lot of time.
In my case I had just added some new image files to the drawable folder and accidentally put a GIF in there with my PNGs. I had not incorporated them into the project at all yet. I removed the GIF and then did a clean and rebuild. That fixed it for me.
I had this exact problem when importing a Udacity Example Program. The Message Pane in Android Studio said the error was failing to load a .PNG in a sub-directory deep in the Project Files.
Turns out the PNG with all of the sub-directory path names was greater than the name length limit defined by Windows 7 (260 characters). I gave the Project a shorter name - to free up some space - and then Android Studio happily compiled.
After you tried make project, clean project, rebuild project but still doesn't work.
Try restart Android studio

Can't create a new Android project with PhoneGap 2.2

I have a problem when I try to create an android project with PhoneGap. (I have windows 8 64 bit).
I put the right paths in my PATH environment variables, but when I try to create a new project, this is what I get:
Cscript not found as an internal or external command... (bad translation from French but you get the point.)
This error is new to me, because before it always returned:
Missing one of the following ...
How can I fix this error?
Though you may have the right PATH variables, you might not have the latest version of ANT or missing the commons-codec. I answered this question in another thread, so you might want to take a look there and see if any of those apply.

Android OCR Application Using Tesseract

I am currently developping an android application based on OCR (Optical Character Recognition). I've downloaded the "tesseract- android" project that contains tools for compiling the Tesseract, Leptonica, and JPEG libraries for use on Android. I am developping via Eclipse on Windows Vista OS.
I've also downloaded the necessary tools (android-ndk;apache ant..), and I've done carefully all the steps to build this project and add it as a library to my basic application.
My app consists of opening the camera for taking a picture and then processing this picture via tesseract API in order to transform it into text.
My question is:
1. Is it true that this procedure doesn't work under Windows OS?
2. When compiling, I am having the following error:
"java.lang.IllegalArgumentException: Data path must contain subfolder tessdata!"
What could be the potential error? The concerned portion of the java code is:
File myDir = getExternalFilesDir(Environment.MEDIA_MOUNTED);
TessBaseAPI baseApi = new TessBaseAPI();
baseApi.init(myDir, "eng");
I've also tried to use "/tess-two/external/tesseract-3.01/tessdata/tessconfigs" instead of "myDir", but the error remains the same.
I would highly appreciate any help.
Thanks in advance.
Q1. It should work on any operating system, I've been able to ndk-build on Win7, Mac OS Lion, and Ubuntu without any issues.
Q2. Make sure that you have permissions to write to the external storage, and have sufficient space to do so.
If that still fails, have a look at the DDMS and see the file explorer and double check your application is setting up the directory structure and copying over the traineddata.
I had an odd issue where it was creating the eng.traineddata file, but it was 0 bytes which led to all sorts of odd issues.
You could also create the directory structure manually to get you progressing, and fix this initialisation issue later on (but don't forget it!)
I was facing the same problem. Worked for me when I removed "tessdata" from the path.
Before (fail): path = "/mnt/sdcard/tesseract/tessdata";
After (success): path = "/mnt/sdcard/tesseract/";
Then, baseApi.init(path, "eng") worked with no exceptions.
Of course, tessdata folder should be in the path with the desired.traineddata file.
Path errors while compiling native stuff usually is not related with your java code. Your java code would be responsible for runtime problems. Check your build scripts and post more log messages.

Categories

Resources