AlexVPerl
AlexVPerl

Reputation: 8026

Speed-up Android Studio Builds

Perhaps a known question, but looking for ways to speed up Android Studio builds. Mine are about 20-25 sec, not terrible, but somewhat a nuisance when trying to test incremental changes.

Obviously getting a faster CPU would help, but looking for software level tweaks / tips to Android Studio if there are any.

Thanks.

Upvotes: 3

Views: 3025

Answers (3)

Ashish Kumar
Ashish Kumar

Reputation: 1126

few commands we can add to the gradle.properties file:

org.gradle.configureondemand=true - This command will tell gradle to only build the projects that it really needs to build.

Use Daemon — org.gradle.daemon=true

  • Daemon keeps the instance of the gradle up and running in the background even after your build finishes. This will remove the time required to initialize the gradle and decrease your build timing significantly.

org.gradle.parallel=true -

Allow gradle to build your project in parallel. If you have multiple modules in you project, then by enabling this, gradle can run build operations for independent modules parallelly.

Increase Heap Size — org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m

-XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 - Since android studio 2.0, gradle uses dex in the process to decrease the build timings for the project. Generally, while building the applications, multiple dx processes runs on different VM instances. But starting from the Android Studio 2.0, all these dx processes runs in the single VM and that VM is also shared with the gradle. This decreases the build time significantly as all the dex process runs on the same VM instances. But this requires larger memory to accommodate all the dex processes and gradle. That means you need to increase the heap size required by the gradle daemon. By default, the heap size for the daemon is about 1GB.

Ensure that dynamic dependency is not used. i.e. do not use

implementation 'com.android.support:appcompat-v7:27.0.+'. This command means gradle will go online and check for the latest version every time it builds the app. Instead use fixed versions i.e. 'com.android.support:appcompat-v7:27.0.2'

Upvotes: 0

oliro Amuri bonface
oliro Amuri bonface

Reputation: 84

Using android studio is quite a painful experience, there are few things i have noted and i hope they can help.

  1. Running android studio and an emulator at the same time leads you nowhere especially if you have a slow CPU and less RAM.

    How i do it?

    • Do the development on a PC(am using Win10), build a signed APK copy it to my device and test the compiled version. Whenever i make changes i have to repeat the build process! Its faster for me than debugging direct through the emulator.

    • Disabling most services on the PC works pretty well with me. Open - RUN -type 'msconfig' - load basic devices and services. Then restart the PC. start android studio and see if anything changes.

    • In both situations i try as much as possible to avoid the emulator

    • For database testing you can use a separate machine with test data or open 'services.msc' and enable your database and web server + Network access.

Upvotes: 1

AlexVPerl
AlexVPerl

Reputation: 8026

I was able to reduce build times to 3-5 seconds.

  • Assigning more RAM used by Android Studio & Gradle
  • Configuring compilation to run in parallel
  • Compiling on demand

RAM settings are an absolute MUST in my opinion - after giving it 2GB (I have 24GB with plenty to spare) the UI is fast and snappy & code editing is very fast, no lag at all.

Here is the full list of instructions I used:

Android Studio RAM Settings: https://extremegtx.wordpress.com/2015/01/08/android-studio-speed-up-studio-and-gradle/

Instructions are for Windows, if you're on MAC use the following path instead: ~/Library/Preferences/{FOLDER_NAME}/studio.vmoptions

Gradle Settings: http://jimulabs.com/2014/10/speeding-gradle-builds/

For reference I am running an overclocked Xeon X5650 @ 3.85GHz and compiling a pretty big project with lots of libraries and dependencies.

Upvotes: 4

Related Questions