12

Whenever I make a code change in the Android Studio (version 3.0.1) I need to clean before I build in order for that change to take effect. Making a change and hitting the green arrow build/run button looks like it builds but the new changes are not incorporated unless the project is cleaned beforehand. For example, if I add some logging then build/run, the new logs don't appear until I clean then build/run again. This seems to be the case for almost all changes. Sometimes it works, most of the time it doesn't.

The compiler should detect changes to the code and rebuild those files every single time. It feels like they prioritized build speed over correctness. Has anyone else solved this problem? If not then is there some setting that forces a clean before every build/run?

Mostafa Arian Nejad
  • 1,278
  • 1
  • 19
  • 32
Clark Battle
  • 630
  • 1
  • 8
  • 16
  • Perhaps this is fixed in 3.1? – Clark Battle Mar 14 '18 at 21:16
  • Instant Run is disabled – Clark Battle Mar 14 '18 at 21:44
  • Recompiling modified code and immediately installing updated app works fine for me in AS 3.0.1. Have you tried to make the app and then run it? Click the green hammer and then press the play button. Which OS btw? – ahasbini Mar 14 '18 at 21:49
  • This has been happening for months. I shouldn't have to press two buttons in order to get a reliable build. The same thing happens with InstantRun (which is why I disabled it). MacOS. – Clark Battle Mar 14 '18 at 22:22
  • I just changed a log then pressed the green hammer before running it. The old log showed up. Then I cleaned and ran it again and voilois! The new log appears. – Clark Battle Mar 14 '18 at 22:25
  • Ok, let's try this differently to check if it's AS or just the project, create a new project in AS and add/modify logs and check if it's not applying the modifications properly. If it is, then this is project related (specifically the one ur working on), otherwise it's AS related and should probably reinstall it – ahasbini Mar 14 '18 at 22:37
  • I have two separate projects going in two separate AS instances. One for the main product and another to test proof of concepts. It happens with both of them. – Clark Battle Mar 15 '18 at 17:34
  • I'm not sure i got ur comment, the idea is to create a new project from scratch that has no added libraries or complex code, it is only created with the default project template. If u've test it with logs and finally still getting old logs then it's appearantly a problem with AS, otherwise it's a problem with the other projects ur working on. If you meant test proof concepts project is a project with modified code or libraries and dependencies, then this is not what i meant as this project might have modifications that are causing it – ahasbini Mar 16 '18 at 14:17
  • Did you ever find a working solution to this? – Yousif Touma Feb 24 '20 at 11:01

5 Answers5

16

I had the same issue after updating Android Studio to version 3.1. It seems that the Before launch action of the default run configuration has been changed to Instant App Provision. Check it out and change to Gradle-aware Make here:

Run/Debug Configurations window

4emodan
  • 955
  • 1
  • 9
  • 17
2

This suddenly started: Code changes were not being reflected on the app / were not taking effect.

My "Run / Debug configurations" settings were as said by @4emodan.

Still, i was facing the problem.

"File -> Invalidate Caches / Restart ..."<br>

made it.

This could have been the result of my machine intermittently rebooting (because of hardware issues).

sifr_dot_in
  • 3,153
  • 2
  • 33
  • 42
1

I experienced that when I left my Android Studio opened for a long time. The solutions I found were:

  1. Hit the "Sync Project with Gradle files" button.

enter image description here

  1. Restart Android Studio.

I hope this helps you.

0

I found that I had to force the apk to install on every build - or risk that some of my changes will not be present. It seems that Google has broken something with the instant run in AS 4.1.2 -- to fix it uncheck "Skip installation if APK has not changed" in the "Run app" dialog.

Android Studio 4.1.2 Run Dialog

Lee Hounshell
  • 842
  • 9
  • 10
-4

I am using android Studio for about 2 months, this never had happened to me. For me I did a clear and rebuild project.

Diego Alves
  • 2,462
  • 3
  • 32
  • 65