user16983
user16983

Reputation: 121

Android Studio-wont remember new edits and automatically reverts to old versions of files sometimes

Every once and a while I have an issue with the new Android Studio. Sometimes while editing, if I make a mistake in one of my files, then try to build it, Android studio will come back with some "Gradle" error. It will then automatically REVERT back to my original code (thus deleting any of my changes). I do not necessarily like this behavior, but I could deal with it. However... sometimes, in the course of SAVING and editing, it gets into this weird state where Android Studio will REMEMBER the error, and wont let me correct it. I.e. it will keep restoring the OLD version of the file, with the error in it, no matter how many times I try to correct it and re-save it. An example of this is as follows. In the following XML document fragment, I mistakenly added the [android:backcolor="#00000000"] to one of my XML layout files...

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@android:id/text1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:textAppearance="?android:attr/textAppearanceListItemSmall"
          android:gravity="center_vertical"
          android:paddingLeft="16dp"
          android:paddingRight="16dp"
          android:textColor="#111"
          android:background="?android:attr/activatedBackgroundIndicator"
          android:backcolor="#00000000"
          android:minHeight="?android:attr/listPreferredItemHeightSmall"/>

After trying to build, Android Studio came back with the following error: "Error:(1, -1) Gradle:No resource identifier found for attributed 'backcolor' in package 'android'.

Of course, I tried to simply DELETE the offending line that I added to return my code to its original state, before I added the line. I saved it (i.e. save-all/etc...) then tried to rebuild. To my dismay, Android Studio RESTORES the bad version, reinserting the erroneous [android:backcolor="#00000000"] line again back into the file.

I have also tried SAVING (save all) exiting out, going back in, the rebuilding it again, and just about every variation of this. Though the ONLY way that seems that will correct it sometimes is to completely exit out of Android Studio, start it back up again, and try again.

I am guessing that this is really a "feature" and has something to do with source control, and/or Gradle, and that I just don't fully understand it yet. I am also guessing that there is some setting somewhere to adjust and/or correct this - but I am clueless as to what is going on and what to do to fix it.

Is there a way to correct this annoying behavior of Android Studio?

Upvotes: 12

Views: 7483

Answers (6)

Majid M. Alzariey
Majid M. Alzariey

Reputation: 483

I just had the same error and made me go crazy I solved it by copying my project file to another directory and then importing it as a new project and the problem disappeared

Upvotes: 0

santhosh m
santhosh m

Reputation: 1

To save the latest edits, click on the particular file in project window and select synchronize, and rebuild the code. then the latest edits will be saved.

Upvotes: 0

CKP78
CKP78

Reputation: 650

I've had a similar issue when I make a mistake in my strings.xml file, for example when I have an apostrophe without preceding with a '\'. The trouble is that when the build fails, Android Studio automatically opens app\build\intermediates\res\merged\debug\values\values.xml to show me the broken string. If I then try to correct the string in that file, it doesn't do any good because when I try to rebuild, strings.xml is still broken. The crucial thing is to make sure that you're making the correction in strings.xml rather than the values.xml file.

Upvotes: 15

Martin O&#39;Shea
Martin O&#39;Shea

Reputation: 432

I still have this issue, the only way I have found to fix it is to go to the terminal in android studio and run

rm -R app/build/intermediates/data-binding-layout-out

Android Studio is failing to delete the last build of the layout, when you try to compile again. Once you do it manually everything is back to normal.

Upvotes: 1

Silvans Solanki
Silvans Solanki

Reputation: 1267

I have the same issue, but i followed following steps and it resolved my issue,

1) Edit your layout file and open the same layout file in notepad, if you can see updated data in notepad then its Studio Synch issue. then re-synch project.

2) If your edited layout file is not reflecting new changes in notepad file then, first re-synch Studio project and followed step 1.

I hope this will resolved your issue as well.

Upvotes: 2

Neoh
Neoh

Reputation: 16174

While this issue still occasionally happens (as of currently the latest version is 0.5.+), a simple workaround is to manually edit the xml file with a text editor, then save it. Android Studio will then force resync those files.

Upvotes: 0

Related Questions