Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Android Studio rebuilds project so slow even when no changes in sources?

Tags:

When I make some changes in source code, Android Studio (actually gradle) needs to rebuild the project. It's obvious.

Why the second build takes almost the same amount of time like the first build, even if I haven't made any changes in the project? When I look into GradleConsole it waits on "assembleDubug" task. I think gradle should be aware there're no changes and shouldn't waste so much time on it.

like image 349
klimat Avatar asked Nov 12 '14 15:11

klimat


People also ask

Why my Gradle build is slow?

Dynamic Dependencies slow down your build since they keep searching for the latest builds every time. To improve the performance we need to fix the version in place. Use only those dependencies that you need.

Why does Android studio take so long?

According to Android Studio's official system requirements, it takes at minimum 3 GB RAM to run smoothly. Honestly, its a lot and I believe that is the biggest cause of being it too slow all the time.


2 Answers

Finally, I found the solution: turn on Offline work for gradle.

enter image description here

or using CLI:

./gradlew --offline assembleDebugOrWhatever

like image 118
klimat Avatar answered Sep 29 '22 18:09

klimat


Does the gradle console say :app:assemeble UP-TO-DATE ?

If you take a look at the run configuration, you might notice at the very bottom Before Launch: Gradle-aware Make

This is just telling it to recompile(if necessary) before running, but that detection is delegated to Gradle. Gradle will only actually recompile if it detects that it needs to, but the assemble task must still attempt to run to detect UP-TO-DATEness. So it says it's running it, but its not actually doing anything. When I run it two times in a row, the first time it takes a while to do everything, BUT the second time it just runs through the task list pretty quickly (with a bunch of UP-TO-DATEs) and deploys to phone/emulator.

like image 23
loosebazooka Avatar answered Sep 29 '22 19:09

loosebazooka