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

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

Related

Android studio messed up every xml file. How to resolve it? [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 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.

Project build.gradle file won't open, Android Studio

This is the first time I've encountered this issue with Studio. For both the project and app level files, when I double click to open build.gradle I get the following problems:
Android Studio 2.3 - File opens, but displays "Loading" indefinitely.
Android Studio 3.0 - File doesn't even open at all. Clicking on them does nothing.
Has anyone else seen this behavior before? And solutions? Advice would be appreciated.
I had the same problem. This plugin was causing it: 'Android Method Count'.
I deleted the plugin, and it worked
delete xxx.iml file, if that still doesn`t work, restart Android studio more.

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

AndroidStudio doesn't recognize R

I am teaching android app programming at a highschool. I found Eclipse to fragile so we are now trying out Android Studio. But a couple of students get that Android Studio with R. in red font, showing that it is not recognized.
This happened for example when the student copied the contents of my files.
It sometimes happens when you open a proyect from other sources. Just Synchronize it or press Ctrl-Alt-Y.
R.java file issues : 1) check the naming convention of images in drawable folder with size.
2) check the style of your application
In your case it may be missing style .. So upadate the style in value folder as per application .
The most common reason for this error is bad XML coding. For example using android:src="#drawable#drawable/picture" in ImageView will give you R error as it will not let R.Java file to build. Its hard to trace such errors as XML file will not show any error.
Also take a look if your resources are of good quality!
Hope it helps! Cheers
Build -> Clean Project
Tools -> Android -> Sync Project with Gradle Files
and all OK!
Try adding the following:
android.enableAapt2=false
to gradle.properties and Refresh:
You can also do the following: Clean Project and Sync Project with Gradle Files.
try importing your project :
To migrate existing Android projects, simply import them using Android Studio:
In Android Studio, close any projects currently open. You should see the Welcome to Android Studio window.
Click Import Non-Android Studio project.
Locate the project you exported from Eclipse, expand it, select the build.gradle file and click OK.
In the following dialog, leave Use gradle wrapper selected and click OK. (You do not need to specify the Gradle home.)
Android Studio properly updates the project structure and creates the appropriate Gradle build file.
First if the existing project was developed in eclipse you need to import the project and then check what are the error. If your students are coping codes from your project then after coping the codes they need to clean and sync the project. If still your problem not solved try this in android studio :-
File/invalidate caches/restart.
Hope it helps you :)
Especially, for regeneration of R.Java file.
If you have tried all these options:
Clean Project
Rebuild Project
Invalidate Caches / Restart
deleted .gradle folder
deleted .idea folder
deleted app/build/generated folder
checked your xml files
checked your drawables and strings
and still face problem then check your classpath dependency in your Project Gradle Scripts and if it's, this:
classpath 'com.android.tools.build:gradle:3.3.2'
then downgrade it to, this:
classpath 'com.android.tools.build:gradle:3.2.1'
clean and rebuild it will sync your project.
I had the same issue, and the lint gave me a hand...
If you're using lint, it can help too.
In gradle.build(Module:app) add the lintOptions sub-element in android element as shown below, then lint will fix it for you!!.
android {
lintOptions {
abortOnError false
}
}
I hope it helps!!

Resources