Android Studio runs old code BUT JUST SOMETIMES. It is fricking annoying

4.6k views Asked by At

I use Android Studio 4.1.1

Sometimes when I edit/add new code to my project, it doesn't refresh. AS simply runs the old code. Sometimes I have to add empty new lines and run it again to make my modifications effect.

I would like to turn off every caching and smart speed run bs in order to make this laughable death star IDE work for once in the life, doing one thing properly, instead of doing 1000 things badly.

How is it possible that when they make an update, fixing/adding 2 new things but make worse/broke 3 old ones?

I tried to turn off instant run but it is not even among options.

Thanks in advance.

10

There are 10 answers

0
Mustafa Ibrahim On

Try to close Android Studio and then delete .gradle folder and then start AS again , this what I did when it happen to me, and it did the trick for me!

This is folder exist in :

C:\Users\userName\.gradle
0
Wilson Tran On

Try #1: Update to the latest distributions Gradle in gradle-wrapper.properties file and clean project.

# 6.8.2
distributionUrl=https\://services.gradle.org/distributions/gradle-<latest-version>-bin.zip

Try #2 (A temporary alternative): Use the Android Studio beta version in the meantime there is a new AS version.

0
Toufiqul Haque Mamun On

Uninstall android studio and sdk files also (try to delete all files regarding android studio from c drive)...Then install android studio in another drive and download the sdk files. It works for me hopefully also work for you.

1
sidiboss224 On

if you had to install gradle. you can empty your caches with this command in your android folder mac ./gradlew clean windows gradlew clean

0
ALUFTW On

It's a known issue in Android Studio.

Follow these steps:

  1. Make a copy of the project to a new folder.
  2. Inside this folder delete the following files:
.iml file
.idea folder
.build folder
.gradle folder
  1. Open Android Studio
  2. Select 'File > Import Project...'
  3. Select the new projects settings.gradle file and click 'open'
  4. Rebuild again (it might need to install the dependencies)

From now on it won't happen again to your project.

0
Himesh Perera On

Might not be the best solution but it works for now.

Just go to "File -> Settings -> Build, Execution, Deployment -> Instant Run" and just disable it. With this Android Studio builds from scratch each time but it's better than not building it right.

0
Amin Mousavi On

I have this problem sometimes too. I found out that the problem is with gradle build cache. I just disable it and everything works fine again. You can check your gradle.properties to see if org.gradle.caching is set to true or not. If you have this setting then try to disable it and see if it fixes your problem or not.

Note that disabling it might increase your build time.

0
Kaustubh J On

Oh yeah, this used to happen with me initially. Resetting the gradle file or forcing a clean up of the project will yield correct results, but is also irritating to do manually after each minor code change (specially if you're working in sub modules.

The reason why the app refuses to update to the new code is due to something called as Instant Run swaps. Basically there exists hot, warm and cold swaps that is used to speed up build time, however this also causes the situation that you're facing. Read up more about Instant Run here -> https://android.googlesource.com/platform/tools/base/+/studio-3.0/instant-run/README.md

As for disabling Instant Run, go to Android Studio Settings/Preferences -> Build,Execution,Deployment -> Instant Run -> Untick Enable Instant Run checkbox

Now each time you build your app you'll notice higher build time, but your code will be updated in the app build.

1
Grisgram On

Have you tried disabling the build cache in gradle.properties?

android.enableBuildCache=false

After setting this it could help to use File -> Invalidate Caches and Restart a last time. From then on, it should do what you want at the cost of a bit build speed (but honestly I don't see much difference in speed since I turned that off).

In addition, as @Himesh Perera said, turn off that instant run. It causes lots of trouble.

2
oleg.svs On
Try this settings:
Run -> Edit Configuration...

1 2