27

inside build.gradle we can add that params

android {
    dexOptions {
        incremental 
        preDexLibraries
        jumboMode 
        javaMaxHeapSize
    }
}

but documentation is too low

http://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.DexOptions.html#com.android.build.gradle.internal.dsl.DexOptions

boolean incremental

Whether to enable the incremental mode for dx. This has many limitations and may not work. Use carefully.

boolean jumboMode

Enable jumbo mode in dx (--force-jumbo).

boolean preDexLibraries

Whether to pre-dex libraries. This can improve incremental builds, but clean builds may be slower.

1) which limitations are in incremental?

2) what is jumbo mode?

3) what is pre-dex libraries?

Alessandro Scarozza
  • 4,273
  • 6
  • 31
  • 39
  • 1
    Possible duplicate of [how can I use Android dexOptions?](http://stackoverflow.com/questions/28927255/how-can-i-use-android-dexoptions) – Tobias Oct 01 '15 at 15:05

1 Answers1

28

first of all lets see whats dex file. in pure java when you compile the java code,it will be compiled into a .class file while in android your java code will be compiled into .dex file. (both are bytecodes but different)

incremental: it means Gradle will use previous dex file and appends the new changes to them (not building them again every time).

the answer of your first Q: e.g. one of the limitation were you couldnt use it along with multidex* (though this limitation was solved - for sdk versions 21+ incremental builds are possible for multidex apks by rebuilding only the affected dex files)

-note: you dont need to worry about this limitations anymore because incremental option is true by default since Gradle version 2.1.0

multidex: this option means compiling java code into multiple dex file you dont need this unless your code methods outnumbers the max limitation on a single dex file (64k methods)

jumboMode (the answer of your second Q): there is also a limitation for strings count in the dex file enabling this option will extend the strings count in dex file (this option is true since Gradle 2.1.0 so you dont have to worry about it either)

preDexLibraries (the answer of your third Q): it builds dex file out of libraries so it can be used in incremental builds (not building dex files every time for libraries). so using this item when clean build makes everything a little slower.

Amir Ziarati
  • 14,248
  • 11
  • 47
  • 52
  • 1
    to sum up: with Gradle 2.1.0 or higher do not need to set any of these parameters to speed up build – Alessandro Scarozza Oct 12 '16 at 09:02
  • 1
    Not true about multidex and predexLibraries. These two are not true by defualt. Every feature that wants to be added as default to gradle firstly is added as incubating feature (means you can use them but they are not stable and may have problem). But after some versions it gets out of incubating state and it gets default. – Amir Ziarati Oct 12 '16 at 09:10
  • multidex is not in question because the meaning is clear – Alessandro Scarozza Oct 12 '16 at 09:14