Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to speed up Android Studio compilation process

Latest update: Check out Android Studio 2.0 (preview) Instant Run it is awesome!!!!

I have found some tips (Building and running app via Gradle and Android Studio is slower than via Eclipse) to speed up the compilation process of Android Studio (Gradle) but I still think it is way too slow. It takes about 15 seconds to compile the project and run on the device.

The gradle.properties is already set to:

org.gradle.daemon=true

org.gradle.parallel=true

Edit: Awesome!!! Colleague of me reported that Jack and Jill might be the solution: http://www.infoworld.com/article/2856113/mobile-technology/androids-new-jack-and-jill-compilers-head-uphill-to-developers.html I'm reading into it.

Checkout this explanation: https://www.saikoa.com/blog/the_upcoming_jack_and_jill_compilers_in_android

Edit 2: New info on Jack and Jill!: http://tools.android.com/tech-docs/jackandjill

Edit 3: Android Studio 2.0 seems to release us from all the burden! Check out "Instant Run". http://android-developers.blogspot.nl/2015/11/android-studio-20-preview.html

like image 853
Ben Groot Avatar asked Apr 29 '14 14:04

Ben Groot


People also ask

Why is Android Studio running so slow?

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. The android developers are always complaining about the speed of Android Studio and how its slow ALL THE TIME.

Is Android Studio heavy?

In the previous versions, the android studio was more heavy software Google is updating it and making it more scalable for developers. But it is even also heavy software which will suck your computer's ram.


2 Answers

There are two main tasks to configure your build to reduce the build time.

First, you have to configure your compilation with special flags to make it faster. Edit your gradle.properties or local.properties files as follow:

org.gradle.daemon=true org.gradle.jvmargs=-Xmx3072m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 org.gradle.parallel=true org.gradle.configureondemand=true android.enableBuildCache=true 

Explanation:

  • At least 3gb of memory are required by the new option included in Android Studio 2.2 dexing-in-process. If your computer doesn't have enough memory you can adjust this attribute to something more appropriate for your setup.
  • Build Cache is a new feature introduced in Android Studio 2.2 that improve a lot the builds. More info here http://tools.android.com/tech-docs/build-cache . In Android Studio 2.3 or superior is true by default

With this configuration, build time is often reduced from 2-3 minutes to 30 seconds or less. The most important part is the configureondemand attribute. More info here to configure Android Studio parameters

First, one is compiling your project with a minSDKVersion >= 21*. If your app has lower min SDK version you can create a special productFlavour for development purposes as follow:

productFlavors {      production {         minSdkVersion 15         ...     }      development {         minSdkVersion 21         ...     } } 

*Important, with Android Studio 2.4 this is not needed anymore because the IDE make this automatically.

like image 165
Aracem Avatar answered Sep 28 '22 06:09

Aracem


Check out Android Studio 2.0 PREVIEW! Much faster!

Supports Instant Run, provide faster emulators and is based on IntelliJ IDEA 15.

http://android-developers.blogspot.nl/2015/11/android-studio-20-preview.html

like image 36
Ben Groot Avatar answered Sep 28 '22 07:09

Ben Groot