简体   繁体   中英

Android studio - MainActivity not declared over and over

I'm using Android studio 3.4.1 on Windows 10 x64 and I'm constantly getting same error over and over. I can't run the app, because "MainActivity is not declared in AndroidManifest.json", and all code that uses something that requires permissions (NFC, read/write files, atc.) is marked as error, and the message is claiming that the permission is also missing in manifest.

These errors can be simply solved by Syncing grande files, as stated in this question: The activity 'MainActivity' is not declared in AndroidManifest.xml

However, after few minutes, these errors are back there again!

I've tried restarting the IDE many times, invalidating caches, syncing gradle many times... But nothing helps. I got these errors, I sync gradle, errors are gone, I run the app, make tiny changes in code (like changing string in setText or changing textview margin), try to run it again, and the error is back. I sync gradle again, error is solved, I run the app, then I leave the IDE, Google something, and when I return to the IDE, the error is again back, even if no changes were made to the code.

I tried to Google this issue, but I was only able to find questions where this happend once.

Obviously there something that makes the Android Studio "forget" manifest every few minutes. The issue started to occur after my computer once lost power and shut down, so my first idea was corrupted files (as it could have happend while Android Studio was saving something), but if I ran the app after grande sync, it works fine, and it lasts few minutes before the errors are there back again.

So, as this issue happening once has been asked many times about, and many times there were different replies, I just started trying other suggestions. I came acros this reply: https://stackoverflow.com/a/52687462/6357453 which suggests deleting folders with cache and other stuff Android Studio has created. I did and as of now, it's been more than an hour without this error, so this propably solved the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM