Android Studio — Build Time hack
Problem:
The web is full of Android developers complaints about slow Android Studio, slow indexing & slow Gradle build.
One observation I noticed: My command line build was slower when my Android Studio was running. Tested my hypothesis with closing Android Studio and building from the command line.
Script:
So I came up with the idea to suspend Android Studio while building through the command line and resuming Android Studio once build is over. Written a small shell script wrapper over ./gradlew for same :)
Tested only on Macbook pro !!
Usage:
Just replace ./gradlew
with ./gradlewSuspendAS.sh
Example usage:./gradlewSuspendAS.sh :app:assembleDebug
Results:
I got a build time boost of ~ 50%+
Pretty useful for big apps with multiple modules. It's not guaranteed to give you build time boost every time. But it works most of the time. After all, it's a hack 😜
Hypothesis:
Suspending Android Studio suspends it’s all child processes and you have more CPU bandwidth, memory available for command-line builds
Note: You can’t do anything in Android Studio while the build is running, as it is in suspended mode. Keep your Calm & Happy coding :)