Danail
Danail

Reputation: 10583

Optimizing build time in Android Studio

I've tried building it:

It takes >40s EVERY time. It doesn't matter if I change anything or not. Building it after "gradle clean" takes >50s.

I hope that I'm doing something wrong. Eclipse/ant could build consecutive builds WITH CHANGES in <10s.

Any help how to bring this <10s appreciated. Yes, we have a lot of modules, some jar libraries, some maven dependancies. Still don't get why would it take >40s for two consecutive builds with no changes.

Gradle used: 2.2.1 Android studio: not really relevant, usually building it only with Gradle.

EDIT: adding some profiling logs.

:app:dexProjDebug 22.541s

:app:shrinkProjDebugMultiDexComponents 4.279s

:app:compileProjDebugJava 3.478s

:app:packageProjDebug 2.591s

:app:processProjDebugResources 2.590s

:app:packageAllProjDebugClassesForMultiDex 2.536s

:app:createProjDebugMainDexClassList 2.126s

Upvotes: 18

Views: 933

Answers (5)

Kaveesh Kanwal
Kaveesh Kanwal

Reputation: 1763

Download Genymotion emulator. It is very fast and good to run android apps. It will save you a lot of time. Here is the link - GenyMotionDownload

Upvotes: 0

Ariel
Ariel

Reputation: 251

One of the most significant build time reducers is the preDex task. Check whether preDex is running in your build. It increases build time the first time you run it, but dramatically reduces build times in subsequent builds, as most of your SDKs and libraries will already be dexed. Note however that it won't run under some conditions, e.g. if you use multidex.

Btw Google are well aware of build times with Gradle and Android Studio and are going to introduce significant improvements in upcoming releases, including Jack and Jill which will allow compiling from source code directly to dex. You can already try to experiment with them - see here: http://tools.android.com/tech-docs/jackandjill.

Also worth watching this video from recent Google I/O: https://youtu.be/f7ihSQ44WO0?t=327

Upvotes: 1

Jocke
Jocke

Reputation: 424

If possible, update to Gradle 2.4. It's significantly faster (claiming 20-40%).

Upvotes: 1

kevinpelgrims
kevinpelgrims

Reputation: 2156

If you have no changes to the other modules, you can build the app itself using gradlew :app:build. This will eliminate the time Gradle spends on building the other modules. You can build any module separately like this as well, using gradlew :moduledirectoryname:build. If you need to build one module and the app, you can execute both tasks at once to avoid going through Gradle's configuration stage twice: gradlew :app:build :moduledirectoryname:build

Upvotes: 1

Bhisham Balani
Bhisham Balani

Reputation: 228

You need to properly define inputs and outputs even for library projects with source code. (Gradle Documentation). Do you get UP-TO-DATE message when you rebuild second time onwards?

Upvotes: 1

Related Questions