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