5

I am using android studio 3.3, my project is using kotlin 1.3.20 with build gradle 3.3.0

however when i try to open xml file, it open different file with the right file name and the right file path:

enter image description here

And when i try to see this xml file in my Git, my file is normal

enter image description here

when i try to run this project, it run with no problem at all. i already try to invalidate caches/restart but the problem still exist.

this error affecting random xml files. some of my xml layout files open my kotlin file. some of them open auto generated file

please help.... is this something to do with error indexing? how can i fix this?

UPDATE :

found someone who might have the same problem with this, in google issue tracker : https://issuetracker.google.com/issues/122988154

UPDATE 2 :

this issue is not just happen in xml file but also in kotlin file.

i try to open my activity file, but it open one of data binding generated classes

wood wood
  • 101
  • 7
  • It might be a cache issue, just try to restart with clean cache. – Akshay Paliwal Feb 06 '19 at 04:58
  • I see this issue a lot, it looks like a bug in android studio. check this https://stackoverflow.com/questions/53403502/strange-error-in-colors-xml-file-in-android-studio – karan Feb 06 '19 at 04:58
  • you can try git revert once....if you haven't made any major changes...as you are saying on git it's showing correct code... – Amit Jangid Feb 06 '19 at 04:58
  • @AkshayPaliwal already try it but not working – wood wood Feb 06 '19 at 05:09
  • @AmitJangid i can't revert my git since there is no change at all.. my remote repo == local repo – wood wood Feb 06 '19 at 05:10
  • @KaranMer hmm i think so.. yesterday all is fine. and today i just open my project to start working and this happen.. – wood wood Feb 06 '19 at 05:13
  • 1
    delete wrong file and then do rebuild , invalidate cache it shows error , and then paste deleted file again . – Chetan Joshi Feb 06 '19 at 05:25
  • @ChetanJoshi thanks it works. apparently this is a bug from android studio and there is no way we can realy fix this. it can appear anytime in any project. this is the only way we can do – wood wood Feb 06 '19 at 07:10
  • My solution was to open all my xml and Java files in TextPad, add some harmless whitespace to each one before re-saving. It's a bit of a pain, but now the correct files show in the IDE. (Incidentally, I left Android Studio open while doing all this - maybe that was necessary for it to pick up the file changes.) – ban-geoengineering Mar 08 '19 at 13:21
  • Simple Solutions for this situation. **Step 1.** Close Android Studio **Step 2.** Open `C:\Users\renish\.AndroidStudio3.4\system\caches` Folder into your file explorer and Remove all files and folder from caches **Step 3.** Start again Android Studio – Renish Patel Aug 06 '19 at 06:28

2 Answers2

1

So Apparently this issue is bug in Android Studio. after do some research, this bug might be happen not just to xml layout but other xml file too such as resource like dimens, strings, style etc..

finally there is some workaround for this issue that work without reinstall Android Studio. Thank you @ChetanJoshi for the suggestion in the comment section.

Steps:

  • Copy the error xml file to somewhere in your PC directory (as backup file)
  • Delete the error xml file, if there is dialog file usage appear klik delete anyway
  • Copy the backup file and paste it back to where it was deleted
  • Run your project. it should run
  • If you are using Data Binding and there is error appear about auto generated data binding class, Clean Project then rebuild project. if the error still appear try to invalidate caches/restart, rebuild project then run the project
wood wood
  • 101
  • 7
0
  • Restart your Android Studio, if not working, Restart your PC. or
  • Go to plugins -> Android support and disable this. Restart Android studio and enable the plugin again

After that don't forget to Refresh your Gradle project.

Farid Haq
  • 3,728
  • 1
  • 21
  • 15