34

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

Community
  • 1
  • 1
Ben Groot
  • 5,040
  • 3
  • 40
  • 47
  • 1
    I'm not certain if it uses those properties for Android Studio builds. You might want to double-check your options in Preferences > Compiler > Gradle. Aside from that, 15 seconds isn't too unusual (sorry, as you can see, it's unfortunately just slow), but if you include the report output from doing both Android Studio and command-line builds with the --profile option passed to Gradle, we might be able to shed more light on any gains you could achieve. – Scott Barta Apr 29 '14 at 18:10
  • Thanks for the reply! I've checked the compiler settings. They seem to be set on the fastest options possible. I'll create the report and send it over. – Ben Groot Apr 30 '14 at 07:04
  • I still can't find a solution to speed up the process. It is 2014, 15 seconds is just too long for me to wait ;( – Ben Groot Aug 08 '14 at 13:39
  • 1
    I've just calculated how much time I spend waiting on the compiler to finish. It's about 39,2 hours a year! Thats crazy right? My calculation: (15 sec * 5 compilations a hour) * (40 hours a week * 47 actual working weeks) = 141000 seconds a year of waiting! – Ben Groot Sep 05 '14 at 09:30
  • 1
    If you want to speed up your builds, you'll need to provide more information on how big your project is, how everything is configured, and where it's spending time in the build. There isn't any information in your question that would enable someone to help you. – Scott Barta Sep 05 '14 at 14:08
  • You're right, I need to provide more info. Sorry for that, I need to make some time for it. One thing I can already say is that we have the multiple project on multiple Mac laptops with different specs (new, fast ones and old slower ones). The compile times differ from 15 sec to 45 seconds on older machines. I'll provide you more info. – Ben Groot Sep 05 '14 at 14:19
  • The variance in build speeds is likely due to memory pressure on older machines, and also disk (somewhat due to swapping from not enough RAM); it depends on your project, but I'm guessing it's not likely to be that strongly CPU bound. Android Studio + Gradle is a memory-hungry combination, and we're not likely to be able to make a big dent in that. I would recommend 16GB of RAM (8 GB at a bare minimum) and an SSD. – Scott Barta Sep 05 '14 at 14:25
  • I did every suggestion and still 1:52 when rebuild , hmm wasted day and half when migrating eclipse huge project to android studio complex gradle build system, I should hang myself , but wait its a nice day and I can still use good old eclipse with manual build, now I see and I am happy how QUICK ECLIPSE ACTUALLY IS !!!! :) – Renetik Dec 11 '14 at 12:06
  • Have you tried using Jack? – Ben Groot Dec 12 '14 at 09:48

3 Answers3

23

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.

Aracem
  • 7,227
  • 4
  • 35
  • 72
1

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

Ben Groot
  • 5,040
  • 3
  • 40
  • 47
  • Note: I found out that I needed to update all my Android served libraries to 23.1.1 – Ben Groot Nov 25 '15 at 15:41
  • Is this ever coming to intellij? Its a while now when they announced its in Android Studio but it doesnt seem to work in Intellij – Srneczek May 13 '16 at 15:56
1

Tips to speed up android studio

  1. Enable Offline Work

  2. Improve Gradle Performance by adding following code in gradle.properties

org.gradle.daemon=true
org.gradle.parallel=true

Step by step guide:http://www.viralandroid.com/2015/08/how-to-make-android-studio-fast.html

Sajan Rana
  • 803
  • 7
  • 9
  • Let's keep these answers varied and focus on the particulars of the OP question. re: http://stackoverflow.com/a/34828203 ... http://stackoverflow.com/a/34827929 ... http://stackoverflow.com/a/34827858 ... http://stackoverflow.com/a/34827827 ... http://stackoverflow.com/a/34827788 – Drew Jan 16 '16 at 14:46