14

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.

Adam Varhegyi
  • 11,307
  • 33
  • 124
  • 222
  • Happens to me too. It's really annoying when I rule out a potential solution simply because Android Studio failed to deploy the new code. – Gavin Wright Feb 25 '21 at 15:17
  • 1
    @GavinWright I exactly know what you are talking about. I have to add stupid toasts to see if the code is updated. – Adam Varhegyi Feb 25 '21 at 15:27
  • had you try to clean the projet and rebuild it ? – 钟智强 Feb 25 '21 at 15:52
  • 1
    @JohnMelodyMelissa Yes. Not really helps. This error would happen every day after I start AS. – Adam Varhegyi Feb 25 '21 at 16:03
  • @AdamVarhegyi, now i am curious what could be the problem.... – 钟智强 Feb 25 '21 at 16:04
  • It happens in both on Windows and Mac. On Mac i use Arctic Fox Canary 8, on Windows 4.1.2. It's especially very annoying when you try to build layouts. I change margins or any UI related property and see nothing changed. And rebuild again. It happens more frequently on Windows. – Thracian Feb 27 '21 at 18:52
  • @Thracian It especially annoying when you have a gigantic project which loads for a minute before you can actually run it, then you realize it is the old code... – Adam Varhegyi Feb 27 '21 at 18:53
  • 1
    Same problem here! It's not about gradle version, it's not about sdk, it's not about anything. It's just Android Studio that is getting worse every new release. I hope to find a solution here – Giuseppe Giacoppo Feb 28 '21 at 11:55
  • Final Solution for me check it now : https://stackoverflow.com/a/66487087/11138845 – S_i_l_e_n_t C_o_d_e_r Mar 05 '21 at 05:06

10 Answers10

14
Try this settings:
Run -> Edit Configuration...

1 2

oleg.svs
  • 173
  • 8
1

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.

Wilson Tran
  • 4,050
  • 3
  • 22
  • 31
1

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.

Grisgram
  • 3,105
  • 3
  • 25
  • 42
0

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
dravit
  • 553
  • 6
  • 16
Mustafa Ibrahim
  • 557
  • 3
  • 8
0

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.

0

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

sidiboss224
  • 11
  • 1
  • 4
0

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.

Dharman
  • 30,962
  • 25
  • 85
  • 135
ALUFTW
  • 1,914
  • 13
  • 24
0

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

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.

Amin Mousavi
  • 1,220
  • 10
  • 21
0

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.

Kaustubh J
  • 742
  • 8
  • 9