Android Studio shows wrong file contents

后端 未结 9 1451
失恋的感觉
失恋的感觉 2020-11-21 11:09

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.

<

相关标签:
9条回答
  • 2020-11-21 11:38

    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.

    0 讨论(0)
  • 2020-11-21 11:40

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

    0 讨论(0)
  • 2020-11-21 11:45

    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

    0 讨论(0)
  • 2020-11-21 11:47

    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.

    0 讨论(0)
  • 2020-11-21 11:50

    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
    
    0 讨论(0)
  • 2020-11-21 11:51

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

    0 讨论(0)
提交回复
热议问题