Big build time with Android Studio 3.1

I am using android studio v 3.1. The operating system is Windows 10. Core i5 with 16 GB of RAM. Below is the result of assembly profiling

:app:transformClassesWithDesugarForDevelopmentQuickbuild 35.137s :app:compileDevelopmentQuickbuildJavaWithJavac 31.917s :app:transformClassesWithDexBuilderForDevelopmentQuickbuild 28.579s :app:compileDevelopmentQuickbuildKotlin 20.145s :app:transformClassesWithMultidexlistForDevelopmentQuickbuild 16.873s :app:mergeDevelopmentQuickbuildResources 16.363s :app:transformResourcesWithMergeJavaResForDevelopmentQuickbuild 7.958s :app:transformNativeLibsWithMergeJniLibsForDevelopmentQuickbuild 6.483s :app:processDevelopmentQuickbuildResources 4.835s 

Gradle.properties projects are below configuration

 org.gradle.parallel=true org.gradle.configureondemand=true org.gradle.daemon=true android.enableBuildCache=true kotlin.incremental=true 

still, for any single line of change, it takes at least 2.3 minutes. This problem occurs only in windows, and on ubuntu the same configuration takes 15-20 seconds. What else can be done to reduce assembly time?

+5
source share
2 answers

In ( Android Studio 3.1 ) in gradle.properties add these two lines: -

  android.enableD8.desugaring=true android.enableD8=true 

Also for multisizing you can add

  multiDexEnabled true 

to defaultConfig

+1
source

I wrote below all the usual tricks.

Also on my machines, the battle of Windows against Linux gradle won Linux. However, increasing heap size can help you get closer to ubuntu compilation time.

Increase heap size

Starting with Android Studio 2.0, all dex in the process run in the same virtual machine, and the VM is also shared with gradle. This requires more memory to accommodate all the files.

By default, the heap size under Windows is 1 GB. You must increase the size of the heap. The more RAM you have, the more you can use.

For an 8Gb RAM development machine, I found that a heap size of 3 GB is the best choice. For your 16 gigabyte computer, you can experiment with a much larger heap size.

How to do it?

Add the line below to gradle.properties:

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

Parallelise build

(I saw that you already did this, but I mention here for someone else to read.)

If you have several modules in a project, enable gradle to build the project in parallel.

How to do it?

Add the line below to gradle.properties:

 org.gradle.parallel=true 

On Demand Setup

(I saw that you already did this, but I mention here for someone else to read.)

Gradle provides - an on-demand configuration flag that will only tell gradle to build components that it really needs.

Basically, it tells gradle to configure modules that apply only to requested tasks, and not to configure them all.

This option is usually suitable for projects with several modules, but for note libraries your project may also be useful for using this flag.

For example, a Google I / O application has two Android components (contains source code related to the android application) and a server (contains code related to the backend server). With default gradient settings, they are both configured at compile time.

How to do it?

Add the line below to gradle.properties:

 org.gradle.configureondemand=true 

... or select "Settings"> "Build, Run, Deploy"> "Compiler" and check the "configure on demand" box.

Enable gradle daemon

(I saw that you already did this, but I mention here for someone else to read.)

Gradle runs on the Java Virtual Machine (JVM) and uses several helper libraries that require non-trivial initialization times. As a result, the onset may sometimes seem a little slow. The solution to this problem is gradle Daemon: a long-lived background process that runs your builds much faster than otherwise.

You may not be able to see the time difference in your first build, but build time will decrease in subsequent builds. AFTER gradle, the daemon is initialized.

If you are using gradle version 3.0 or higher, the default gradle daemon is enabled by default. If you work in older versions, this is not so.

How to do it?

Add the line below to gradle.properties:

 org.gradle.daemon=true 
0
source

Source: https://habr.com/ru/post/1276179/


All Articles