Is it safe to delete all the content from .gradle and .idea? - android

I am facing an issue that I can see a suggestion someone made on a blog that supposedly helped them solve the same issue. The suggestion was to delete all content on .Gradle and .idea folder, followed by gradle re-sync and rebuild all.
I am fairly a beginner and I've never done anything like that, so I am scared of any destructive actions I don't know the results of. Is there anything to be afraid of by this action, or would these files just be regenerated again?
If all good, how is it done properly? Via the explorer? Or via Android Studio?
Thanks!

.gradle/ and .idea/ are safe to delete, though I would have the IDE not be open on that project while you do it. If that is your only project, close Android Studio, then delete those directories using your OS file explorer or the command line. Then, reopen Android Studio, and it will recreate and re-populate those directories.

On top of the other answers be sure to save the content already in the files. For instance, in your app/build.gradle file be sure to save content like your SDK version and dependencies. When your app is rebuilt and synced you may have to find code relying on a certain SDK Version or dependency.

Related

I was working on my application, reopened it after a while and all .xml files have gradle content in them now [duplicate]

I have an odd problem with Android Studio.
Here is how my class file looks like on Android Studio
And here is what it looks like on a text editor.
Any ideas why it is happening? I have tried closing then reimporting the project, invalidate caches and restart, clean project, build project, delete .idea folder and .iml files. All of my files are broken when opening in AS but looks fine on text editors.
UPDATE: Quicker solution by the user Hong given below:
Delete the caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches
=====================
Here's what worked for me.
Close Android Studio
Go to C:\Users*your username*
Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
Rename it to something like old.AndroidStudioX.X
Start Android Studio, and when it asks if you want to import settings, choose the old directory
This should fix the issue.
Thanks to the Answer of Asim, I found deleting folder caches fixed the problem for my case (all gradle files in Android Studio show contents that have nothing to do with the actual contents of these files):
C:\Users\my_user_name\.AndroidStudio3.3\system\caches
Edit[2020-07-17]:
This is still happening with Android Studio 4.0, so I have to delete the following folder to fix this problem:
C:\Users\my_user_name\.AndroidStudio4.0\system\caches
Edit[2021-11-08]:
This solution no longer works for Android Studio Arctic Fox. Please see the new answer by Nikunj Paradva. I have used the new solution and it works.
Solution for Android studio Arctic Fox and Higher Versions
Steps
Exit Android Studio
Delete caches folder from
C:\Users\{username}\AppData\Local\Google\AndroidStudio2020.3 // For Arctic Fox
Open Android Studio and your code has being Perfect
Check your Android studio version and Target that version folder at below location
C:\Users\{username}\AppData\Local\Google
Note : AppData folder is Hidden in Windows
Does this situation warrant a bug report?
Yes! In fact this problem has been reported to the Android Studio team, and anyone willing to help us investigate is welcome to contribute there. Thanks!
You can also try the workaround in Hong's answer.
Close Android studio and then delete the caches folder: C:\Users\user_name\.AndroidStudio3.4\system\caches
Try to delete the Android Studio IDE cache data listed below per your platform:
Windows:
%USER%\.AndroidStudio[Preview]_X.Y_
Mac:
~/Library/Preferences/AndroidStudio[Preview]_X.Y_
~/Library/Caches/AndroidStudio[Preview]_X.Y_
~/Library/Logs/AndroidStudio[Preview]_X.Y_
~/Library/Application Support/AndroidStudio[Preview]_X.Y_
Linux:
~/.AndroidStudio[Preview]_X.Y_
See: https://developer.android.com/studio/releases#delete-unused
Updated my android studio days ago and was faced with the same problem. Solved it by uninstalling android studio and reinstalling the previous version set up I had left the SDK intact so I didn't have to re-download them working perfectly guess I won't be updating again soon.
Thanks to #Henry for confirming, by several similarly observed whacko problems the past two days, that my problem is indeed caused by a bug in AS. Follow his links to become convinced yourself. I'll let Henry file the bug report.
So there's no fixing my problem in situ without great effort--wait for bug fix.... which could take awhile.
So here's what I did to work around it and get back to work (it took less than 10 minutes):
create new project with no activity
(Do the rest inside the IDE, not using Windows or DOS.)
copy all .java files into the java folder in the IDE (it's ...\app\src\main\java\)
copy all res folders into the res folder (...\app\src\main\res\)
copy all asset files into main folder (...\app\src\main\assets\)
copy androidmanifest.xml into main folder (...\app\src\main)
do a global replace of old project name to new project name
I didn't change any of the files in the new project's ...\app\ folder because compilation was normal.
(I'll tell you this: when I saw what I THOUGHT were mangled FILES and looked at the History and saw nothing resembling what should have been there, I got a sick feeling, but I immediately opened Windows Explorer, selected all of the project's java files, and opened them, en masse, with Notepad++. Whew. No problems seen. (I didn't really think AS could actually mangle the files and I doubt it ever could. But it did wake me up at 5am!))
copy your android project to another location then open it from android studio
I changed my projects location and it solved my problem. This happened when my system was accidently shut down due to power failure.

Android 3.4+ file encoding error causing projects to fail in loading and file to become unreadable

Ever since i upgraded to android studio 3.4 and going forth to 3.5.3 and i been experiencing projects that i used to work on earlier in the day suddenly fail to load and modules can't be read and opening any files .xml , .gradle all i see is the something like below:
I tried :
resetting the encoding to UTF8 from android studio settings > editor
invalidating the cache and restart
delete the .idea folder and reloading project
Nothing works, unless i have a copy of the same project or have it on Github and clone it again and re open it.
Note:
while the files look like the image you see in android studio, opening any of them in an editor like VScode shows the correct contents of the file
Anyone have a clue, because this is really frustrating
TL;DR
disable Dart and flutter plugins in File > settings > plugins menu,
reopen your project like you usually do.
Extra steps that could help:
clear cache
delete the .idea folder
delete all .iml files from you project as suggested by #Max Shwed
How i got there:
The issue mentioned above kept happening in a number of android projects old and new.
before uninstalling AS an reinstall i thought i give it one last try, i cleared the cache, delted all the the .iml files manually along with the .idea folder.
After that i imported the project and let AS regenerate the deleted files, one weird thing happened is that my build.gralde file was looking totally different there was Dart code inside it and package import from dart, while the file was completely unaltered when opened in any text editor (thankfully AS didn't re-write the file) it was simply built differently in AS view.
Suspecting Dart plugin to be the problem since i have some demo Flutter apps i been working on , i disabled the Dart plugin and just re-opened my project and Voila everything looks fine and project built successfully and run.
i think it's flutter framework issue
but i have a solution that i tried and fixed this
just make right click in your distributed file -> local history -> show history -> and revert one step
it will get your original code without any formatting
and wait for the next flutter plugins to update

Android studio strange behaviour with some files appearing different than how they are

I have a problem with Android Studio that happened all of a sudden today when I opened AS.
As you may see in the pictures, some files are strange.
In this picture you may see that some of the .java files have different icon
And totally wrong content
Same thing happens with SOME of the XML files which have different content
Also some of the PNG images are not displayed in AS.
All files are ok, if for example I open them externally (notepad...) they are ok (luckily).
Is there a way to fix it?
I've already tried to invalidate cache/restart but it didnt work.
Thanks
So, it happened once again, but I've found a quick fix.
I post it as an answer so people can easily spot it.
Quick fix:
Go to the folder "C:\Users\"your user"
Rename the folder ".AndroidStudio3.2" in ".AndroidStudio3.2backup"(name is example)
Launch Android Studio, It will not find configuration files, so it will ask you if you want to import them from the folder ".AndroidStudio3.2backup"
Click yes, few seconds and now you can delete the backup folder cause it will be created another ".AndroidStudio3.2" folder. Notice that I've renamed the original folder instead of delete it for security, and so to avoid to reconfigure Andoid Studio again, but you can choose to start a new configuration if you want.
Once launched Android Studio, click import (gradle...) and import your project.
Everything worked fine after this few seconds quick fix.
Hope it helps.
In fact this problem has been reported to the Android Studio team already.
A workaround would be to delete the caches folder of the Android Studio directory:
C:\Users\USERNAME\.AndroidStudio3.3\system\caches
This at least is the recommendation from the issue tracker and worked for me as well.
The same happened to me when I updated the libraries in gradle kotlin, etc. what I did was to download my project from my version manager and update the libraries one by one and prove the project works.

Removing facebook library Android Studio

I have followed this instruction to make use of the facebook sdk:
using facebook sdk in android studio
but now I don't want to use the sdk anymore. I have removed the entire facebook map from the libraries map. And I removed everything what said "facebook". But still there is a folder in the libraries folder with a file that is called libraries.iml that is coming back when I start Android Studio or while it is active. Could someone explain me how I could get the facebook folder away? Thanks!
You're hitting some known bugs in deleting modules: https://code.google.com/p/android/issues/detail?id=61528 https://code.google.com/p/android/issues/detail?id=64720 (this is most closely related to what you're seeing even though the description seems quite different) and https://code.google.com/p/android/issues/detail?id=61529
They'll be fixed for 0.4.5, and possibly 0.4.4, depending on how things go.
Sorry about the bugs, I know it's kind of a pain.
In the meantime, I'd suggest the following:
Exit Android Studio
Back up your project directory
Make sure the offending library's directory is deleted in the filesystem, and that it's gone from settings.gradle
Delete all your .iml files, and delete the .idea folder from the root of your project
Re-launch Android Studio and re-import your project

android eclipse driving me mad?

I've quite new to Android development and specially Eclipse.
I'm busy on a project called, say 'HelloEclipse'. I've had some major changes ahead, in which I had to some very big changes.
So I made a zip file of c:\workspace\HelloEclipse, placed that in a save place. Went on to work on my project. Few hours later, I wanted to go back to the saved situation. Closed Ecplise, rebooted my computer, because I wanted to make sure there were no locked files. Deleted the old c:\workspace\HelloEclipse folder, place the version out of the ZIP file back.
This resulted in a totally corrupted workspace status. Could not go foward, nor backward. I've ended up, creating a new project, and pasted in everything, took me hours. I think this is quite stupid Eclipse behavior. I've also tried ot, export/import with a archive from out of Eclipse, also not succesfull.
So the two questions;
How am I suppose to save projects (without installing anything like subversion)?
Why is saving the files not enough, and why does that make Eclipse barf?
Thanks in advance!
Dennis
In eclipse if you want to reimport an old project from a ZIP, don't just copy the project files to the workspace, instead, extract the files to a normal dir outside the workspace.
Open Eclipse normally and select File>New Project>Android Project, just as you would to to create a new Android project, but then in the new android project window, you have a radio button giving you the choice to Create project from existing source, point it to the directory where you have extracted your old project and it should be re-imported to the WorkSpace alright.
Or do File>Import>Import existing project into workspace.
But in any case, don't put the files in the workspace manually to avoid conflicts, Eclipse will copy the files it needs itself upon importing.
There are hidden workspace files that you may have missed -- specifically, .classpath and .project. That said, it's a lot easier to make a backup copy (for example, of a released version so you can continue developing while supporting the release) by simply right-clicking on the top-level of the project in Eclipse and selecting Copy, then right-clicking and selecting Paste. The result will be a copy of the project after an opportunity to name the copy.
If you want to zip projects, you can do that by exporting them. If you want to delete existing projects, you should do that from inside Eclipse with a right-click. You can import the zip you previously exported.
If by save, you meant backing up the best something would be to create a local repository. If I were you, I would backup my code in an online repository too; to save it from hardware crashes or other disasters.
In your problem, you could have tried deleting the project alone and import the backup copy(from the zipped file) instead of deleting the entire workspace. Can't pinpoint the exact reason of why eclipse barfed but maybe because it messed up the workspace settings for eclipse. On a related note, I found this on the net.
Eclipse is rather troublesome at times but AFAIK it's the best IDE for android.
First of all, after several months of developing with eclipse I moved to IntelliJ (they have a community edition) and I found it much much better.
In intelliJ you can save local history, for example, you can set-up a label and go back to that label whenever you like without losing anything.
As for eclipse, you probably didn't zip some hidden files or something.
In addition, I remember having some similar problem, I had to resync the files with the project, try this one
Good Luck
I do the same thing with my projects. Instead of going through windows explorer to copy the files, I find copying the entire project from within Eclipse (right click the project in the explorer window pane, click copy, then click outside of the project and click paste) works just fine. When you paste it, you can specify a new save location and project name, which can be your backup space. Then you can switch between versions of the project no problem.

Categories

Resources