13

Is there any way to display which process of my build is the one taking the most time and then try and work around it?

I am using Android Studio. I wouldn't call my project big at the moment but I guess the dependencies I require makes it larger and the build still takes between 40-60 seconds. (down from 90 seconds before removing multi dex)

Here are my Mid 2015 Macbook Pro's specs:

  • Processor: 2.5 GHz Intel Core i7
  • Memory: 16GB 1600 MHz DDR3

I have had to remove part of a dependency to be able to build without enabling multi dex support and this saved me ~20 seconds, however I want to add more dependencies so I need to improve my build time so I can then re-enable multi dex and actually use the dependencies I want to.

I have seen a few posts about modifying Android Studio to speed up the build time but these don't seem to have worked and I would rather see if I could fix the cause.

Here are my current dependencies:

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])

// MY INTERNAL LIBRARIES
    wearApp project(':wear')
    compile project(':ViewPagerIndicator')
    compile project(':connection-manager')
    compile project(':core-library')
    compile project(':activity-manager')
    compile project(':activity-recorder')

    compile 'com.google.android.gms:play-services-maps:7.5.0'
    compile 'com.google.android.gms:play-services-wearable:7.5.0'
    compile 'com.google.android.gms:play-services-location:7.5.0'

    compile 'com.android.support:appcompat-v7:22.2.1'
    compile 'com.android.support:support-v4:22.2.1'
    compile 'com.android.support:design:22.2.1'
    compile 'com.android.support:cardview-v7:22.2.1'
    compile 'com.android.support:recyclerview-v7:22.2.1'
    compile 'com.android.support:support-annotations:22.2.1'

    compile 'com.jakewharton:butterknife:7.0.1'
    compile 'joda-time:joda-time:2.7'
    compile 'com.androidplot:androidplot-core:0.6.1'

    compile project(':ParseLoginUI')

    /*Images*/
    compile 'com.squareup.picasso:picasso:2.3.3'
    compile 'com.makeramen:roundedimageview:2.1.0' // https://github.com/vinc3m1/RoundedImageView
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'io.reactivex:rxandroid:1.0.1'

//    apt 'com.google.dagger:dagger-compiler:2.0'

}
StuStirling
  • 15,601
  • 23
  • 93
  • 150

4 Answers4

6

There are two main things you can do improve building speed:

  1. Offline work:

offline work on gradle

  1. Compile against bigger SDK versions:

This one is tricky. Usually your minSdkVersion needs to be something like 14 or 16. This slow things down. If you compile using minSdkVerison = 22 speed times increase dramatically. You can increase minSdkVersion during development and reduce it when release.

lgvalle
  • 3,712
  • 1
  • 19
  • 14
  • Setting `Offline work` is a hit. However, you must remember to set it off again if you add any dependency – jmm Aug 18 '15 at 13:08
  • I'm afraid on average these methods don't save me any time. Perhaps the offline works but for a negligible 3/4 secs. The minSDK trick didn't seem to have any effect – StuStirling Aug 18 '15 at 13:49
  • Other thing you can do is try to play with DexOptions: `dexOptions { incremental = false preDexLibraries = false }` There is more info here: http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Advanced-Build-Customization – lgvalle Aug 18 '15 at 13:56
6

I have inadvertently fixed the issue I was seeing my end whilst working on other things.

Implementing the external dependency Retrolambda was increasing my build time from ~10 seconds to ~45/50 seconds. Removing this from my application decreased it significantly (by ~40 seconds in fact!).

I removed retrolambda because I wanted to start testing my application and needed the dependencies Robolectric and Mockito. If I used retrolambda at the same time I got an exception along the lines of unsupported major.minor version pointing at JDK 7. The long and short of the story is I was fed up of hacking around my dependencies and build setup just to use retrolambda (Android Studio mimics them anyway in it's code folding).

StuStirling
  • 15,601
  • 23
  • 93
  • 150
1

Using offline mode for gradle can improve build times.

Preferences > Build, Execution, Deployment > Gradle > Offline work

The downside is that you have to turn off offline mode whenever dependencies are updated.

cyroxis
  • 3,661
  • 22
  • 37
0

You could also replace two libraries (picasso and round image view) with Glide and a utility class that will easily do the job of roundimageview library.

Check this post for an example code that transforms image to a rounded one with glide. How to round an image with Glide library?

I'll also suggest you to create Utility directory and place this CircleTransform class into it.

Doing steps above will reduce number of libraries that you use and hence the method count and build time of your project!

Community
  • 1
  • 1
Ivan V
  • 3,024
  • 4
  • 26
  • 36