Decreasing android studio 2.1 build time
Asked Answered
C

3

5

I was using android studio 1.5 earlier and i just upgraded to 2.1.But after the update my builds are taking much more time(from 15 sec to 2 min now)

Things I have tried as mentioned here

Enabled offline work in Settings

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

in gradle.properties file @ C:\Users\.gradle (Windows)

But still no difference. How can I reduce the build time?

Crenel answered 16/5, 2016 at 5:29 Comment(3)
What is the JDK version you are using?@CrenelShaveling
Java SE Development Kit 7 Update 79 Version 1.7.0.790Crenel
Installed the updated version of JDK and check if the problem persists or not.I faced the same problem but after updating the JDK the error was resolved.Shaveling
T
3

From official source:

Windows defender real time protection is causing instant run slow downs. Add your project folder to windows defender's list of exclusion.

The video (Instant Run - Deep dive) on the official documentation page for Instant Run has a mention of this at around 7:40 (timestamp). It is strange that they have not put this down as text.

Tungstite answered 16/5, 2016 at 11:51 Comment(2)
Tried it but with no effectCrenel
have you turned on instant run at all? if not, that should be the first thing to doTungstite
A
1

I also face the same issue with Android Studio

Please uncomment the line

org.gradle.jvmargs=-Xmx1024m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

and increase the org.gradle.jvmargs=-Xmx1024m to org.gradle.jvmargs=-Xmx2048m

in gradle properties file

also include

defaultConfig {
    multiDexEnabled true
}

in your module level build file.

it worked for me, hope it worked for you too..!

Ashcroft answered 16/5, 2016 at 5:51 Comment(3)
Made the change in the gradle.properties file and the build did speed up by about 30 sec but still off by at least 90 seconds compared to the earlier versionCrenel
it will take time in first build but it will decrease time drastically in subsequent buildAshcroft
On my windows machine I run gradle build command first time after starting android studio it took approx 4 min 55 sec because I have 68 unit test cases, then I run command gradle clean to delete cache and again run gradle build command and it tool 1 min 50 sec.Ashcroft
T
0

have you tried instant run?

Steps to enable instant run:

  1. Open the Settings or Preferences dialog.

  2. Navigate to Build, Execution, Deployment > Instant Run and click Update Project

ref: http://tools.android.com/tech-docs/instant-run

some more tips : link

-Enable Configuration on Demand.
-Use Gradle Daemon.
-Newer versions of Gradle and Java are faster.
-Avoid doing expensive things during the configuration phase.
-Don’t use dynamic dependencies (`x.y.+`).
-Parallelize the build.
Thoroughpaced answered 16/5, 2016 at 5:38 Comment(3)
Instant changes is enabled.Many changes do get almost instantly refreshed(10-15 sec) which works for most UI layout xml changes.But Most even small java code changes still take its own sweet time to build.Crenel
@Crenel what was the size of your app now? You should limit adding dependencies or third party libraries on your app, try to minimize it by just copying the class you just need instead of adding it on your dependencies.Thoroughpaced
Apk size is around 4 mbCrenel

© 2022 - 2024 — McMap. All rights reserved.