Unable to view the source code in android studio, while VS Code opened java/XML fine, I restarted with clear cache, UTF-8 to other, sync with file, deleted .idea and restarted but still getting this problem.
May I know is this coming from a virus or any other malware affected android studio / Windows 11...
Even I uninstalled android studio and reinstalled it today but how this coming again is my question...
The given image was my files which were unable to edit or even change a sentence may rewrite unsaved java files with this text.
I already encountered the same issue, I had tried all solutions (delete .idea dir, invalidate cache) but nothing worked.
I had finally uninstall and reinstall Android Studio, the problem had disappeared
Related
After upgrading to arctic fox, I faced this issue. Opened a project I worked previously with older version of android studio was fine, but after restart its files became full with gibberish values. I thought its a hardware failure issue. But this happening again today with other projects, so I want a solution.
After working, closing and reopening the project the files contents became corrupted/changed:
File contents changed on previous project, showing difference with git:
ArcticFoxPatch2, Projects are built with gradle 7.0.2.
Solutions tried:
I have tried potential solution of invalidating cache and restart, but the files stays same.
Android studio warns and suggest wrong encoding but reloading with multiple other encoding did not resolve file contents.
What should be a solution?
Should I change hardware, eg ssd? or downgrade android studio?
Please run android studio like this.
Click Android Studio and click right button on mouse, then click "Run as Administrator".
Hope it helpful for you.
When I wanted to start working on my app again in Android Studio I had this problem that Android Studio would start, but doesn't show a screen. In my Windows 10 taskbar I can see that it runs: Android Studio is running. But it doesn't show a window and it isn't on any other desktop. When I Windows+Tab or Alt+Tab it shows just a white screen for Android Studio. I tried restarting Android Studio, restarting my computer, reinstalling Android Studio and none of these worked this time. Yesterday it worked just fine. I had this problem last week too, but reinstalling worked. Does anybody have any idea what's wrong?
I got the same problem when I Upgrade to 4.0.
Reinstalling application is a waste of time, and it may not work.
You can try to delete the configuration file, its directory is named .AndroidStudio[version] and it is located by default on win10:
C:\Users\[userName]\.AndroidStudio[version]
This operation can make it work successfully on my win10.
Hopefully it helped you.
As stated before,
You can try to delete the configuration file, its directory is named .AndroidStudio[version] and it is located by default on win10:
C:\Users[userName].AndroidStudio[version]
Doing this will probally work, but it will erase all your configurations of the IDE, I learned that if you delete only the file named recentProjects found in C:\Users\[userName]\.AndroidStudio[version]\config\options it works.
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.
This question already has answers here:
Android Studio shows wrong file contents
(10 answers)
Closed 4 years ago.
After a random crash on Android Studio, a lot of my code is being opened by Android Studio as if it was an XML or R.class.
Sample of Corrupted File 1
Sample of Corrupted File 2
Explaning it better: It does correct itself after a fresh install of Android Studio (any version), and it hasn't happened in 3.1.4, but I'm using features from 3.2. After less than 6h coding, a random crash happens on Android, I report it by the AS and this suddenly happens to many of my files, not allowing me to build it again until I reinstall Android entirely.
I'm running AS as an Administrator, and I do have permission everywhere.
My project is not corrupted nor are my files, since every single fresh install simply brings my code back and I can code until any/a random crash happens, creating this AS/Gradle corruption.
As you can tell, even when "corrupted" on AS, my code is actually fine when opened with any external editor, so reverting back my Git code is not enough to make me get rid of this problem (I wish).
Some important things I already tried:
Clear Cache and Restart Android Studio
Use Android 3.2.1 and 3.3 RC
Rebuild Project
Resync with Gradle, FileSystem, etc, etc...
Clear caches from /user/.gradle/caches and from /user/.AndroidStudio3.3/system/caches
Delete .idea and .gradle from the project's folder
Reinstall Android Studio (also tried with both versions)
I found a related issue here, but the guy simply deleted both of those files. But that's something I can't do, since this is happening with my project files. This related issue can be found here.
I also found another 3 or 4 posts, which where never answered with a valid answer and that were "never solved" or were solved by installing a new version of AS. But I'm already trying the Beta and this error/problem persists....
Consider this post a cry for help. This is haunting me in my development in such a way that I simply can't program more than 6 hours before getting this bizarre behavior in each and any newer version of AS.
References:
Related by #Vengat
Related by #CanProgram (since 2.3.3?)
Related by #RmGetty Bautista
Related at KeepCoding
Tbh, android studio sucks at that part. If you encounter that problem, then r.i.p to your code.
The way I tried to minimized the chance of getting my file corrupted is by closing the emulator whenever I finished running the program, and also when it works properly, I copy all the files to a notepad just in case something bad happen.
*and yes it happened right when I wanted to show my assignment in front of my lecturer, thanks to notepad I can retrieve it back
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.