140

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.

enter image description here

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.

Jeongbebs
  • 4,100
  • 7
  • 34
  • 60
  • 2
    That's now the fifth post I see in a short time showing how AS 3.2.1 corrupts files. Seems there is a serious bug. – Henry Nov 01 '18 at 11:17
  • related: https://stackoverflow.com/questions/53099538/how-fix-androidmanifest-xml#comment93094712_53099538 – Henry Nov 01 '18 at 11:40
  • related: https://stackoverflow.com/questions/53058559/android-studio-auto-generated-public-final-class-r-file#comment93016031_53058559 – Henry Nov 01 '18 at 11:41
  • The simplest solution is to create new project and copy-paste files one-by-one instead of wasting time IMO. And I can see that you're using VCS, just checkout all the files. And try again – Shashanth Nov 11 '18 at 14:29
  • That's the simplest but not the best one. I have uncommitted changes on this project and copy-pasting is more time wasting. – Jeongbebs Nov 11 '18 at 14:33
  • Hi, I am facing the same issue, have you find out what is the cause? Thanks – Ricky Nov 13 '18 at 15:05
  • 1
    I saw a post with the same problem, if you are using windows Go to C -> Users -> yourUserName -> and delete the folder of the android studio version you are using (mine is .AndroidStudio3.2) It will delete all the settings you've made and maybe the plugins you have installed – Jeongbebs Nov 14 '18 at 02:10
  • 4
    Facing the same issue. What the hell is going on? – Asim Nov 26 '18 at 07:07
  • I am also having the same issue. Any solutions? – kirtan403 Nov 27 '18 at 14:02
  • Just delete the Android Studio folder `C:\Users\UserName\.AndroidStudio3.2`. Then click android studio again. – Jeongbebs Nov 28 '18 at 03:58
  • Same issue with Android Studio 3.2.1 (win) – fireb86 Jan 09 '19 at 15:39
  • The problem seems to be this bug reported to the Android Studio team. If it's affecting you, we'd appreciate your engagement there to help us diagnose and fix it. Thanks! Please go to http://issuetracker.google.com/119638289, where the work is currently being done :). – Patrice Feb 13 '19 at 00:39
  • Same issue here with 3.3.1 – 3c71 Feb 20 '19 at 14:41
  • Same issue here with 3.6.1, all files were showing up in text editor but one and this one file's content is nowhere to be found. Happened with a Kotlin project. – Lalit Fauzdar Mar 21 '20 at 05:27
  • Same here with 3.6.1 but can be fixed by copy file from text editor(office or visual studio any) and paste it in AS but Some day latter .... same thing happen again ..... huh , any permanent solution please ! – P. Mohanta Mar 30 '20 at 09:01
  • Back here to say same issue with the latest 4.0.1 – Lalit Fauzdar Sep 22 '20 at 11:56
  • 1
    Using Arctic Fox, and this problem still exist. By now we should call it a "feature" rather than bug. – Dfirmansyah Dec 03 '21 at 13:01

10 Answers10

178

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.

  1. Close Android Studio
  2. Go to C:\Users*your username*
  3. Locate the Android Studio settings directory named .AndroidStudioX.X (X.X being the version)
  4. Rename it to something like old.AndroidStudioX.X
  5. Start Android Studio, and when it asks if you want to import settings, choose the old directory

This should fix the issue.

ban-geoengineering
  • 18,324
  • 27
  • 171
  • 253
Asim
  • 6,962
  • 8
  • 38
  • 61
  • 2
    This worked for me as well. Do you know why or what is causing the issue? And why did you try this out of all things? – Eugene H Dec 07 '18 at 14:58
  • 4
    Because every setting Android studio has is in these folders, including all the plugins. Once I realized that my actual data wasn't being changed, this seemed like the logical choice. – Asim Dec 10 '18 at 18:22
  • 1
    My laptop got blue screen several times while working on Android Studio with the emulator and the tomcat server running.. I think the blue screen had somehow corrupted the Android Studio cache. Therefore, deleting the cache folder worked for me.. – Dilini Peiris Aug 02 '19 at 18:19
  • 1
    just deleting caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches worked for me. – Jaspal Mar 31 '20 at 10:13
120

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.

Hong
  • 17,643
  • 21
  • 81
  • 142
  • 1
    This is corroborated by [a comment on the canonical Android Studio bug report](https://issuetracker.google.com/119638289#comment14). – Dana Dahlstrom Feb 20 '19 at 23:27
  • 1
    Thanks for the solution, this issue happened after opening two projects in a different window and integrated firebase to one of those projects. Now it's loading correctly. – Manoranjan Apr 04 '19 at 06:40
  • 1
    The comment for AS4 really helped. in my case, my AS4 caused by BSOD – Yohanim Jul 22 '20 at 11:46
  • 1
    I had a power cut while using Android Studio 4 which seemed to cause some files to show the wrong contents. Deleting the caches folder as described here fixed the issue. Many thanks. – abernee Jul 30 '20 at 09:04
  • 1
    One would have thought that "Invalidate Caches" would have done this job. Thank you for the solution. – Jon Sep 21 '20 at 14:22
  • 1
    Thank you, sir, it's working for me. And something I was not able to see the lib code which I used in my application but with the help of your answer is possible now. – vikas thakur Dec 31 '20 at 04:37
40

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

Nikunj Paradva
  • 15,332
  • 5
  • 54
  • 65
29

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.

honk
  • 9,137
  • 11
  • 75
  • 83
Dana Dahlstrom
  • 306
  • 2
  • 7
9

Close Android studio and then delete the caches folder: C:\Users\user_name\.AndroidStudio3.4\system\caches

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
Kishore Reddy
  • 2,394
  • 1
  • 19
  • 15
  • 7
    This answer has already been posted multiple times. Please only post an answer to old questions if you have a different solution or a significantly better explanation than existing answers. – Mark Rotteveel Oct 23 '19 at 06:43
  • This answer worked for me for Android 3.6.3, and was the simplest and least invasive, and not mentioned directly anywhere else in this question thread. – GSBTom Jun 10 '20 at 15:40
5

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

shizhen
  • 12,251
  • 9
  • 52
  • 88
1

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.

Selaron
  • 6,105
  • 4
  • 31
  • 39
Egesa Michael
  • 53
  • 1
  • 6
  • update android studio is always a mistake... using it is a mistake that google forces us since it can do something decent by itself – Rafael Lima Mar 11 '19 at 18:43
0

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):

  1. create new project with no activity (Do the rest inside the IDE, not using Windows or DOS.)
  2. copy all .java files into the java folder in the IDE (it's ...\app\src\main\java\)
  3. copy all res folders into the res folder (...\app\src\main\res\)
  4. copy all asset files into main folder (...\app\src\main\assets\)
  5. copy androidmanifest.xml into main folder (...\app\src\main)
  6. 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!))

DSlomer64
  • 4,234
  • 4
  • 53
  • 88
  • Quick and easy solution by[Hong](https://stackoverflow.com/a/54509482/9804732)below. In a single step. close AS and Delete everything inside caches folder: C:\Users\my_user_name\.AndroidStudio3.3\system\caches and Enjoy . – P. Mohanta Mar 30 '20 at 09:22
0

copy your android project to another location then open it from android studio

0

I changed my projects location and it solved my problem. This happened when my system was accidently shut down due to power failure.

Aziz
  • 1,976
  • 20
  • 23