Android studio keeps underlining all classes red while saying that R doesn't exist - android-studio

I know this has been asked many times, but usually the advice is something along the lines of "decrease Android gradle plugins version" or something like that. Firstly, that doesn't seem to work for me, secondly, decreasing the version in order to solve this kind of problem doesn't seem like a good practice and I'd like to avoid it (especially since Android Studio warns me I should increase the version back again when I try to decrease it).
So now what exactly is happening + some details that might help:
Every class is underlined with red color in the project explorer and there are loads of "java package R does not exist" messages in the Problems view
When I open any class, suddenly its red underline disappears and there are actually no errors in this class
It happens if and only if AS does an automatic build (I can see "21:03 Auto build completed with errors" in the Event log). When I build manually, there are no errors in the Problems view, and no class is underlined (that is, until AS does auto build again, which happens all the time)
In any way, this doesn't prevent building of the application/APK/AAB, installing it on the phone/virtual, and running it
This has been happening ever since I updated Android Studio to v4.1 (I now use Android gradle plugin v4.1.0)
(Of course, I also tried all the obvious stuff - deleting every temporary/generated file, invalidating cache, restarting, cleaning, etc. etc. Everything I could think of.)

I had a problem like this before, it had nothing to do with the gradle ijust add "import com.package.appname.R;" into myclass and is worked

Related

Android Studio very slow lint

I do not remember the exact version, but about from 3.2, the lint processing of Android studio has become dreadful.
ctrl + b won't work for about 5min after putting the code, and red lines which are supposed to indicate unwritten methods or wrong referencing is completely broken.
I never had such issue on the previous versions, and I don't know what to do with this. I looked through stackoverflow with the tag android-studio, but no one seems to have the same issue, or I'm selecting the wrong keyword for this.
But, all three of my colleagues are having the same issue from a certain version of Android studio.
Is this an issue with vmOption? Please help.

visual layout editor does not allow drag&drop

I'am a newby in android studio and learning a lot, but now have a problem where i cannot seem to find the answer to.
In android studio you can visualy drag&drop your screen.
I have seen it can do al lot (although you sometimes need the xml) but for me it is not working at all.
I mean i cannot drag&drop any widgets on the screen at all.
Tried changing the theme: no help (really tried a lot of them)
Tried a complete new project: same story
Tried other APK verion: same story
Tried Invalidatd caches / restart: no help
Even with a new project (EmptyActivity) it add's a android.support.v4.widget.NestedScrollView and then gives error's on that
(Failed to find style 'coordinatorLayoutStyle' in current theme).
It also gives an error on layout_height/layout_with not being there. But they are there for each widget.
Please do not missunderstand: when i execute the project i runs just fine (both on phone and emulator) but the visual builder for the screen.....:-(
Does somebody knows how to solve this.
If more info is needed please ask.
Any help is more than welcome.
There are several things that could be causing this:
Your caches could be messed up. Try going to
File > Invalidate Caches / Restart ... (I know that you already tried this, but posting for future views.)
Also, make sure that you don't have Drag-n-Drop with ALT pressed only checked in your Settings (Appearance & Behavior - Appearance).
Finally, in a default project created in Android Studio, there are two XML files created for each layout. For example, content_main.xml is embedded within activity_main.xml. Make sure that you are using content_main.xml for your design work.
In the end i fixed it by changing the SDK version in de gradle file.
still do not understand why it was wrong as studio genereded it that way but now it works so.... for me: case closed.

Android Studio 3.1.2 0 - no longer see errors in all files (red underlined)

I feel like I'm going crazy, but since updating to the new version of Android Studio, I can no longer tell which files have errors in them.
Previously, if I made a change in one class, like to a method signature, then all other classes that were calling that method would suddenly be highlighted in red (at that section along the top that shows the path). Now it shows nothing as though my code is good, except when I go to compile, I now get a load of errors in the build tab at the bottom, in a really unhelpful way to navigate through.
Is this something I can switch back to through a setting somewhere? I'm really not sure what to search for, but I've been through almost all of them.
UPDATE :
Following another SO post, I turned on and off PowerSave mode, at the bottom of File menu (in Android Studio). This, temporarily at least, seems to have solved things.
This may be what you are looking for?
Either that or it may be in preferences.

Android Studio Not Recognizing Imports in TextView

I want to watch android sources code, but Android Studio has so many errors in base Android code. How do I fix these?
Since no one has jumped in here to help with this...
The longer answer here is that the imports (in red) are failing because Android Studio can't find them. So all the calls made to those libraries are failing. So ALL your code after that is full of errors.
For instance, the android.annotation.ColorInt seems to be broken. A quick Google search provides THIS: https://developer.android.com/reference/android/support/annotation/ColorInt.html
Which tells me that the reason that dependency is broken is because whatever you have there is deprecated and should now use a new reference.
Continue with this sort of research and your problem is solved.

Android Studio freezes when right clicking the project explorer

I'm using Android Studio 1.5.1 on Kubuntu 15.10 and lately, Android Studio freezes completely whenever I right click into the project explorer. The only thing I can do then is to kill the process.
More oddly, whenever I hover the Help menu with the mouse, the complete OS freezes completely and I have to restart the computer. I am not 100% sure if these two issues are related, but they started at the same time.
Sometimes (about 10% of the time) it works well. I have no idea what influences this pattern, though. This used to happen earlier as well, but much less frequent.
The usage of different color schemes or deactivating plugins seem to have no influence on this behavior. I also did not install any fishy third party software or anything else that could (to my knowledge) have influenced this. Any ideas?
The issue seems to be resolved in the latest stable release (2.0).
I've recently run into this as well. Pointing jstack at the hung process suggests that it's this problem.
Switching to the Darcula or GTK+ theme resolved it for me. Weirdly, I can switch back to the Intellij theme afterwards and the problem stays fixed - I just have to switch to GTK+ or Darcula at some point after startup but before triggering a right-click menu.
Edit, 1 day later: In a deeply unimpressive plot twist, this solution no longer works for me. I've changed nothing since yesterday, but now attempting to switch themes triggers the lockup ಠ_ಠ
Edit, 1 day, 5 minutes later: After a restart the situation improved slightly - changing the theme now works again, and avoids the freeze-on-rightclick failure. I'm finding it difficult to take this as much of a victory.
Edit: As karpfen notes below, this issue has been resolved in the latest release. Huzzah!

Resources