Android studio messed up every xml file. How to resolve it? [duplicate] - android-studio

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.

Related

could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRootsManager

My project works and builds successfully on my Mac but I cloned from github and although Android Studio appears to work normally, the project wouldn't build. I setup this project using Kotlin DSL.
Gradle sync failed: could not find extension implementation class org.jetbrains.kotlin.idea.scripting.gradle.roots.GradleBuildRoot
Tried invalidate cache, removed all .gitignore rules but it's still the same.
Any ideas?
I had the same issue (Note : Running Linux/Ubuntu 20.04 LTS and Android Studio 4.1.1).
Things I tried that did NOT work and error persisted :
Invalidate Caches / Restart
Reboot
Nuking the .gradle and .m2 folders
Android Studio re-install
Downgrade kotlin gradle plugin from 1.4.21 to 1.4.10
What did work :
Moving the project to a different folder/location on disk and open Android Studio
As soon as I moved the project back to the original location I would start getting the same error. This lead me to believe it was some sort of caching issue, separate from the caches "invalidated".
Solution :
Android Studio / Intellij creates a hidden folder called :
On Linux :
AS : ~/.cache/Google/AndroidStudioX.X
IJ : ~/.cache/Jetbrains/IntelliJIdea2020.X
On Mac :
AS : ~/Library/Caches/Google/AndroidStudioX.X
IJ : ~/Library/Caches/Jetbrains/IntelliJIdea2020.X
On Windows:
AS : %HOME%\AppData\Local\Google\AndroidStudioX.X
IJ : %HOME%\AppData\Local\Jetbrains\IntelliJIdea2020.X
Inside this folder are other various folders, however I removed the relevant workspace file (workspace/[project name].[hashed value].xml) after which problem went away when opening the project again, from its original location.
So it appears that "Invalidate Caches / Restart" does not "Invalidate" all caches!
I hope this resolves you problem!
Update
As this answer has had quite a few upvotes it would appear that this might be a ongoing bug with Intellij. If anyone has this problem, before resolving with the suggested solution consider checking there isn't an open issue on the bug tracker and submitting a new issue : https://youtrack.jetbrains.com/issues
Feel free to edit this update with issue if one is opened.
Update 2
Issue opened by #GeniusRUS :
https://youtrack.jetbrains.com/issue/KT-44937
For Mac users delete the following file:
~/Library/Caches/Google/AndroidStudio4.1/workspace/<your_project_name>.58dfbe93.xml
PS: Thanls #Mark Keen for solution.
basically i deleted .idea folder and then invalidate and restart ... error goes away and built successfull.
This probably isn't the "correct" solution, however, it worked for me. I had to download a newer (Canary) Version of Android Studio to get this error message to go away and to finally build my Android project once again. I found this YouTrack JetBrains issue where people also suggested reverting to previous, known working, versions of Android Studio to get their projects to build again.
This is a SUPER frustrating issue and I hope that one of the approaches resolves your build issues for you!
Here are the Android Studio Versions Download page for convenience.
After moving projects and files around I had also the honor to enjoy this error in Android Studio 4.1.1 (under Windows 10). Unfortunately, none of the above solutions worked for me but they helped me to narrow down the issue.
So, I found that there is a folder with workspaces under:
%HOME%\AppData\Local\Google\AndroidStudio4.1\workspace\
There are a couple of *.xml files named like the android projects. I deleted the one that didn't work.
Then switched back to Android Studio and used the Files > Invalidate Caches / Restart... feature. Android Studio restarted and the problem was fixed.
Bonus: How I found the workspace folder?
I used the Procmon.exe from Sysinternals where I filtered by the Process Name = studio64.exe. I then used the elephant-with-the-arrow button (Sync Project with Gradle Files) in Android Studio. At the end of the recording there was the workspace folder that Android Studio used just before Gradle failed.
I added a "problem" ticket to YouTrack, where I described my case in detail.
The support agent said the issue has already been fixed in the IDEA 2021.1 platform.
And also gave recommendations for this case
Link to issue
https://youtrack.jetbrains.com/issue/KT-44937
I fixed the issue by changing the root project directory name. You can try that.

Android Studio broken .studio instead of classes shows incomprehensible pieces – xml

I started the studio and see such a picture, considering that all the classes are broken and everything is lit in red - the project is going and working. Help me fix it. Invalidate does not help. Instead of classes in general pieces of markup ...
Close Project
Try Removing .idea folder from your project.
Restart your project again in android studio
I have delete caches folder from C: Drive. after open project in an Android studio.
C:\Users\admin.AndroidStudio3.3\system\caches
link here

Android Studio shows wrong file contents

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.

Indexing freeze with message: Indexing paused due to batch updated

I've updated Android Studio to version 3.2.
After that update one of my projects don't want to index.
It freezes with the message
"Indexing paused due to batch update".
How can I fix this?
File gradle-wrapper.properties:
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
File gradle-properties:
org.gradle.jvmargs=-Xmx1536m
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
I faced the same issue with Android Studio 3.2. Invalidated the cache and restarted Android Studio, but it still did not work for me. Then I just re-imported the project and it worked!
Just Restart (File > Invalidate Cache & Restart > Just Restart)
I faced this issue in Android Studio 3.+ when forcefully close Studio in between some gradle process.
Pressing the play button worked for me. It finished indexing and installed the apk in seconds. The catch is that I have to do this every time and batch does not seem to update.
Click on the play button to the right of the progress bar.
Press the play button to the right of this message and the issue would resolve.
You have to do it every time, because right now the problem is systematic and there is no solution to stop it from appearing.
I invalidated the cache and restarted Android Studio. That worked for me.
You can do this by:
File > Invalidate Caches / Restart > Invalidate and Restart
I faced this issue many times and what I did everytime is:
Firstly, click on the processing bar on the bottom of the android studio.
A pop up window will appear on the screen like this-
Click on the red circled Play button and let the process complete.
Please note that you will have to repeat this everytime you face this issue because this is some kind of bug or something in AS version 3.2
Optional: click on (-) minimize button if you want to the pop-up to minimize
I faced the same issue, it seems that Android Studio messes up the cache.
Go to File > Invalidate Caches and Restart
Then on the Pop Up that appears choose Invalidate and Restart
Seems like there is an issue with Android Studio itself. I fixed the issue for now by following these steps:
Click File > Invalidate Caches / Restart
On the pop up choose Invalidate and Restart
Invalidated the cache -> restarted Android Studio -> re-import the project from the project location. Its worked for me
This is an issue in Android Studio since v3.2, I have posted an issue in Android Studio Issue Tracker, it's being finally accepted. Waiting for them to solve it.
Here is the issue tracker, you can follow up from here.
please star the issue as well to help solving it.
Stay Connected to internet.Let the batch to be updated.Wait one time and it will be easy the next time. OR...Click on the play button.
I saw this error and none of the solutions posted here worked for me. I had a specific scenario (see below), and I could get rid of the problem in my specific scenario. Not sure if the OP had the same scenario, by here are my two cents:
In my specific case I had two projects open in Android Studio, where one of the project was from a sshfs-mounted directory (the other project was local to my computer). I believe that made Android Studio throw the "Indexing paused due to batch updated" message on, strangely, both the projects.
To get rid of the error on the local project, I had to close the remote mounted project. On closing that project, the message was gone for my local project.
Hope that helps.
Close your project
Go to your project root directory,
Find and delete the xxx.iml file, the .idea and .gradle folders
Re-open your project using Android Studio.
I had the same issue and I fixed by do the following:
Click File --> click on Invalidate Caches / Restart
You will see a pop up--> select Invalidate and Restart
I did it by exporting the project into zip file and open it like normal. you can export by clicking the file navbar and choose export to zip file
I faced the same Issue but the situation which lead to this was different:
I created a remote branch on the project's repository on GitHub and it was empty.
And then I checkout to that branch locally while android studio was running.
I then deleted the local repository and created it again but this time it was not empty. Further I pushed the code to the remote branch as well.Now I thought that it will start the project normally but again the same happened.it resulted in an IDE error.
To solves this issue I deleted that local repository and again re-imported it.Than it started correctly.
None of the other answers worked for me. Not even pressing the "play" button. All that worked was closing the project and re-opening it via "Open an existing Android Studio project".
The effect only lasts for a single session. As soon as I close and re-open the project, or AS 3.3, the problem re-appears.
Deleting C:\Users\<user>\.AndroidStudio3.3\config\options\recentProjects.xml (before starting AS 3.3) is an alternative way to accomplish the same thing.
EDIT
Upon upgrading to AS 3.3.2, this solution no longer worked. However, after an "Invalidate Caches and Restart", the problem disappeared.
Click on play button twice and then go to file->Invalidate Caches / Restart...
repeat this process every time whenever you face this issue.
I solved it by deleting all the *.iml files and the .idea folder
I faced the same issue, because my AS version is not the same with gradle plugin's version.
This issue coccus randomly in Android Studio V3.+ [Issue tracker:https://issuetracker.google.com/issues/118523471] .
There might be multiple reasons for this issue but it is mainly either ".gradle" related or ".iml" file related IntelliJ/Android Studio configurations.
Possible solutions:
Click on play icon under the processing bar (on the bottom of the android studio). But be aware that multiple clicks may also kill the the indexing process.
Invalidate cache (File -> Invalidate Cache & Restart -> Just Restart)
Clean ((Build -> Clean project) and Rebuild (Build -> Rebuild Project)
Sync Project with Gradle Files: Available options (depending on the Android Studio version) at
Tools -> Android -> Sync Project with Gradle Files
button available at top left corner in Android Studio's toolbar
File -> Sync Project with Gradle Files
Delete the .idea & .gradle folders and .idea & .iml files from the project root directory and re-import the project
I have faced this issue quite a few times and got rid of then by using one or more of above solutions.
But in some scenario nothing of the above solutions may work (as recently I get trapped-in). In this case I have to recreate the same project from scratch and copied back the required files into it. But ideally this should not be the solution. Please let me know if any other possible solution is there.
Invalidate cache and restart did the work for me. Now, the build is compiling in seconds.

Android Studio is showing wrong project name

I have an Android Studio Project , the original name was GUI-refresh-by-time however it is showing Typer in the main screen.
But when I open the project, it becomes GUI-refresh-by-time
My .idea/.name is called "GUI-refresh-by-time"
How can I resolve this issue? It might lead confusion specially when you have too many projects.
Ok, I solve it anyway.
The problem occurs because I have another Android Studio project name
Typer , both of them are located in the same Folder Location root/Gui-GUI-refresh-by-time and root/Typer
Basically this root/Typer does not have .idea/.name so I decided to delete the Typer project Folder and reopen my Android Studio, after then it works.
you could just remove the project from the workplace by saving it elsewhere and try reimporting it

Resources