Flutter project, some filenames not identified as .dart files in Android Studio - android

Picture of problem
I already tried to modify the type analysis of android studio, restarted and recreated the project.
I reinstalled Android Studio and tried different Flutter SDKs and Android Studio versions, but I cannot work with .dart files named "login_event.dart" and "auth_service.dart", because Android Studio isn't recognizing them as .dart (no linting, just plain text, as you can see on the icon type in the picture).
I have over 40 other dart files in the project which all are working fine.
Just these two specific names can't be identified.
Even if the compilation of these to files is working, is is still annoying not to have advantages of normal dart files while coding.
Why this error occurs only exclusively with this naming, globally on my system regardless of AndroidStudio version and project is very incomprehensible to me.
It looks like Android Studio just doesn't want to recognize some names.

call flutter clean or to invalidate it using File > Invalidates Cache / Restart... ? solved the problem

Related

Android studio not installing some specific packages

I want to install other pack ages apart from the ones that come with compose.
Example:
For lotties files animation
implementation "com.airbnb.android:Lottie:3.7.1"
And
For curved bezier bottom app bar
implementation"com.etebarian:meow-bottom-navigation:1.3.1"
It keeps giving error messages from
CheckDebugAarMetadata
Downwards
#Opeoluwa-Muritala, I've tried both of the libraries in my Jetpack Compose Project. It's working perfectly fine. Maybe the error is regarding the Gradle cache or the builds cache.
You can try
• Clean and rebuild the project,
• Invalidate & Restart the Android Studio,
If still not works then you can try another option is, close the Android Studio and then rename the '.idea' folder to '.idea_old', and the '.gradle' folder to '.gradle_old' and remove the build folder under the app folder.

Android 3.4+ file encoding error causing projects to fail in loading and file to become unreadable

Ever since i upgraded to android studio 3.4 and going forth to 3.5.3 and i been experiencing projects that i used to work on earlier in the day suddenly fail to load and modules can't be read and opening any files .xml , .gradle all i see is the something like below:
I tried :
resetting the encoding to UTF8 from android studio settings > editor
invalidating the cache and restart
delete the .idea folder and reloading project
Nothing works, unless i have a copy of the same project or have it on Github and clone it again and re open it.
Note:
while the files look like the image you see in android studio, opening any of them in an editor like VScode shows the correct contents of the file
Anyone have a clue, because this is really frustrating
TL;DR
disable Dart and flutter plugins in File > settings > plugins menu,
reopen your project like you usually do.
Extra steps that could help:
clear cache
delete the .idea folder
delete all .iml files from you project as suggested by #Max Shwed
How i got there:
The issue mentioned above kept happening in a number of android projects old and new.
before uninstalling AS an reinstall i thought i give it one last try, i cleared the cache, delted all the the .iml files manually along with the .idea folder.
After that i imported the project and let AS regenerate the deleted files, one weird thing happened is that my build.gralde file was looking totally different there was Dart code inside it and package import from dart, while the file was completely unaltered when opened in any text editor (thankfully AS didn't re-write the file) it was simply built differently in AS view.
Suspecting Dart plugin to be the problem since i have some demo Flutter apps i been working on , i disabled the Dart plugin and just re-opened my project and Voila everything looks fine and project built successfully and run.
i think it's flutter framework issue
but i have a solution that i tried and fixed this
just make right click in your distributed file -> local history -> show history -> and revert one step
it will get your original code without any formatting
and wait for the next flutter plugins to update

How to Index files on android studio

TLDR; Is there a keyboard shortcut or a command to index the whole project in android studio
I noticed some drawable resources were still unresolved when I copied them in the res/drawable folder in android studio.
I did a File > Sync with File System thinking that would resolve the issue.
But it didn't solve it as they were still unresolved.
The build is successful and the app runs but the IDE is not happy for some reason.
It works when I restart android studio but I don't want to restart it every time I add an asset.
As android studio indexes the files sometimes saying 'indexing files' at the bottom. So I searched for it and there doesn't seem to be a keyboard shortcut.
Another issue:
The image assets get added as filename (v24). Why is that?

Why does Android Studio 3.2.1 fail to interpret file content correctly--not even close--for half my project class files? [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: Cannot resolve symbol, however build runs OK

Some time ago, I imported Urban Airship into my Android studios project. Everything was fine until recently when it can no longer resolve the corresponding symbols. The code runs fine, it just gives me the red errors if I open the files and so intellisense cannot resolve.
I've tried deleting everything and checking out the project again (no iml files or .idea/.gradle directories are committed), deleting my AS settings from the user directory, invalidating caches from the file menu.
So I ended up having to completely reinstall Android Studio due to having made a custom proguard jar and Android not understanding it can overwrite it and the issue went away. This was an update from 1.1 to 1.2, which made a completely different install directory for all of the components. I'll update if I find any more details.

Categories

Resources