My application has a bunch of librarys that are essential that is why I was forced to use multidex support library and it works nicely. But where the problem shows is in the gradle buid speed. It takes on average 2minutes to build and when I am developing and testing this is quite annoying.
Is there a way to speed up my debug builds?
Go in setting , search compiler , type "--offline" in Command line options and than compile.
Multidexing uses more memory. As you get closer to your max heap size in Java you'll find Java spends more time doing GC than it does doing any real work, this can slow things down a lot.
I'd strongly recommend increasing the max heap size when using multidex. Add the following to the android closure in your build.gradle file to make the max heap size 4GB (Make it smaller if you wish):
Changing MinSdk to 21 made everything back to normal for me.Now everything compiles in like 6s
Android Studio 1.3 (currently in Preview 3) is using a new build system which improved gradle build time (really, like 10-30x faster).
More information in the Live Session at Google I/O 2015
This is no longer needed with the latest Android Studio 3.0
You can speed-up your development builds by specifying the minimum SDK version = 21.
Official documentation includes a whole section about that.
Example (from documentation):
Once you added the product flavors, you can use the
devDebug
task (instead of defaultdebug
task) for your development builds:- from command line: run
./gradlew installDevDebug
- from Android Studio: open Build Variants window and select the
devDebug
build variant.You should, of course, work against a device whose SDK >= 21.
There's also a solution for those who don't want to use flavors. As suggested in this gist, dynamically calculate the
minSdkVersion
value:In this example, we're checking if
devMinSdk
property defined, and if true - we're using it. Otherwise, we default to 14.How do we pass
devMinSdk
value to build script? Two options:Using command line:
Using Android Studio preferences:
Go to Preferences (Settings on Windows) -> Build, Execution, Deployment -> Compiler -> put
-PdevMinSdk=21
in Command-line Options text box.