I'm working on a 1M+ LOC with tons of XML files. The problem I usually get is that the R.xxx classes are usually unresolved after reopening Android Studio (currently I use AS 3.4, but this happened long before). The only solution I know is: close AS, remove .idea folder and then open AS again. This solution works but quite annoying since I lost my workspace information (like opened files history).
I wonder any of you guys experience this and if you have a better solution, please share with me.
I guarantee that the project I am working on has correct configuration and no syntax errors.
Related
I have an Android Studio (Bumblebee 2021.1.1) project, composed of a main app plus two imported libraries, one Java and one native, developed by me.
At a certain point in time - I cannot recall any event related to this, - the compiler has stopped recognizing the code changes.
If I write something random (e.g. my name, or "aaaaa") within a code that has thus far compiled successfully , the IDE marks this in red as error, however, when I press Ctrl+F9 ("Make Project"), the compiler does not detect any change in code and ends with "BUILD SUCCESSFUL". This happens also when I explicitly save the modified code. The only way I have to make the compiler detect the change is to launch "Rebuild Project". I have tried all the solutions proposed in Android communities (delete ".idea" and ".gradle" folders, invalidate cache, etc.), to no avail. To be noted that I have other projects on the same PC with the same Android Studio instance, but the always-successful-build only happens with the project mentioned above. Can anybody please help me? This is very frustrating, because, even for a tiny code modification, I have to rebuild all, which is very time consuming. Thank you very much.
Please note that I've read "File was loaded in the wrong encoding:'UTF-8' in IntelliJ IDEA" this, and everything else related to this issue that I'm having which is going to make me rewrite everything that I did in my project in past 2 days.
Now, the only reason I'm asking this question, is because if someone else faces this problem in future, it'd possibly have a solution by then?
So here is the problem:
I was working on my app which is already present on Play Store, I made all the changes in code, and wanted to add stuff in old java file. But, I was suddenly greeted with this beautiful thing:
Now, the error first said "File was loaded in the wrong encoding UTF-8" and gave me bunch of options to change my encoding. Now, as a programmer, I know if I have any issues, I should Google them, and found all the answers related to this issue, and I tried all those, fortunately, after trying all those answers, above error was gone, and only one "warning(?)" remained saying "Java file does not declare any class". Now, the amazing part is, if it was encoding error from Android Studios Code editor, it should have been totally fine if I opened it in another text editor right? I opened it using "Brackets" & also "Notepad", but I was again greeted with this beautiful thing:
Now, I'm totally clueless as to where I went wrong here, as some classes are working fine (most of those are Activities), but a lot of them which are not activities, are all gone and have become something like this. It's a nightmare and everything I wrote in past 2 days seems to have gone(because my last push was 2 days ago, I know I'm dumb). XML files are fine, and only Java files have this problem.
Things I tried:
Deleting Android Studio settings from C:\Users\PersonWhoDidntPushChanges\.AndroidStudio3.4
Reloading File encoding with UTF-16 and then again back to UTF-8. (Please note that only Reloading does not write the contents on disk and change the original encoding, there's a different option for that)
Deleting .idea folder from the project, and reloading the project.
Usual stuff, Invalidate Caches/Restart, Clean Project, Rebuilt Project.
Please also note that app ran fine and Android Studio did not give me any error until I actually opened this file, and when I saw this file in such format, I opened bunch of other classes to find those stopped working too. Any help regarding this matter would be appreciated.
I'm using
Android Studio 3.4.2
Build #AI-183.6156.11.34.5692245, built on June 27, 2019
JRE: 1.8.0_152-release-1343-b01 amd64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
Windows 10 10.0
EDIT 1:
Some XML files were also changed by Android Studio. The only solution that I found currently is just replacing the complete project with the one that I had on Github. Apparently some of the libraries have also changed (FloatingActionButton).
I found the solution. Just click on that activity... As in my case it is
Main3Activity
Right click and open in explorer. The open the file in notepad ++ and copy paste to again android studio.
I have faced the same issue and after some struggle, I solved the issue so I am
sharing here so that you can also solve it.
First of all, close the android studio and then delete the AndroidStudio folder which
are stored in c derive.
Eg:- C:\Users\XXXX
Now you need to open android studio and install all the file which are asking by
Android Studio.
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've just inherited a fairly large Android codebase at work and I've come across a perplexing problem with Android/Android Studio after I've imported the project:
Opening some of the project files, I see a bunch of code highlighted in red (AS reports "Cannot resolve method XXXX"):
But the project builds just fine (!):
The methods in question do not exist AFAICS (I've done a global search for it) and yet, the project builds just fine.
I feel silly asking this but does anyone here know what's going on?
Earlier I have same problem because Android Studio makes a lot of files as caches and does not delete them. This can cause trouble when there is a need to make new files, so clearing caches will clear the old cache may be it solve your problem
go to file menu and Click invalidate Caches / Restart.
Well, it turned out the project was using Lombok and those methods were auto-generated and Android Studio does not know how to how to handle them unless you install the Lombok plugin for Android Studio.
Have you not done a right-click on getPaymentsComponent() and chosen Go->Definition to see where it takes you ?
I updated tools in my Eclipse first by going to Help->Check For Updates and installing everything i that it suggested. Then by going to Window->Android SDK Manager and updating multiple things including my SDK version.
After I have finished my update all my Android projects got a nice red box with an x inside it. I explored the projects and noticed that none of them had any errors inside the project just the project itself had the error icon. I searched online and i found that other people had similar problems. So i thought i found the solution. Alas after cleaning and building the project I got additional error icons next to multiple java files in my projects. Eclipse cannot locate the automatically generated R files when it tries to import them and all the imports are selected red.
I tried deleting the whole content of .android directory (starting with specific few files then the whole content) but that did not bring desired results.
So i have deleted the newly generated files and restored all the old ones.
When I clean and build the projects again all the errors disappear but only until I try to run the project again and then same error appears:
Your project contains error(s), please fix it before running it.
I have also found a related question. It claims that there must be a problem with my xml files. I did not modify any of my xml files since updating the tools so I dont know what could cause them to have errors.
Any ideas as to what is going on??
I've found that eclipse is now picking up errors that it didn't pick up before, because they updated lint, you may have to check all your files and see if there is an error because of this, if it doesn't work try removing Android from the build and reattach it, clean the project, build project, make sure the activities are using the right R files and check what lint says, its like a little square with a tick in it I think.
I had exactly the same problem, solved by removing any imports of R in my code and then cleaning the project
Strangest thing just happened. Even though I have done this 2 times before I have again deleted all my files in .android folder exited my Eclipse and opened it back up again. All the errors were gone and most of my projects work correctly. I have spend a lot of time on this problem and i dont know how it got resolved but Im glad its working again.