Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 214
user16983 Avatar asked May 28 '13 22:05

user16983


People also ask

Why is auto complete not working in Android Studio?

if the autocomplete isn't working for you in Android Studio, just press File and uncheck the Power save mode, it should work fine after that. if power save mode is already unchecked then first check then uncheck them.

What is default config in Android Studio?

Specifies defaults for variant properties that the Android plugin applies to all build variants. You can override any defaultConfig property when configuring product flavors.

What is Android Studio stable version?

Android Studio Dolphin | 2021.3.1 Patch 1 (October 2022)


2 Answers

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.

like image 161
CKP78 Avatar answered Sep 21 '22 10:09

CKP78


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.

like image 40
Silvans Solanki Avatar answered Sep 19 '22 10:09

Silvans Solanki