Speeding up your Android Gradle builds (Google I/O '17)

Android Developers · 64K views · 2017 · 40:16

Open on YouTube

Testing, debugging & developer toolsSoftware performance & optimizationSoftware practice, open source & careerstalkdated

Why Stack Overflow recommends it

Stack Overflow users link it when answering questions about slow Android Gradle builds and when explaining why compile was deprecated in favor of implementation and api.

Recommended by 5 people across 5 different months, 2016 to 2021.

What it is

A Google I/O 2017 session from the Android team on how the Android Gradle build system works and how to make builds faster. It covers new build performance strategies and the Android Gradle plugin 3.0 changes, including the move from compile to implementation and api.

What people said

Recommends Sotti · 2016-05 · Stack Overflow · on “To run dex in process, the Gradle daemon needs a larger heap. It currently has approximately 910 MB”

Update from June 25, 2017 At Google IO 2017 there was some updates about this topic. It's not recommended anymore to set the flag on the dexOptions, so if you have something like the next, you can delete it. dexOptions { javaMaxHeapSize "2g" } Source: Speeding Up Your Android Gradle Builds [this video] Original answer: Android Studio 2.1 enables Dex In Process which shares the VM with Gradle to improve build times. Due to this, it's necessary to increase the size of the Gradle daemon to incorporate those Dex processes. At least it's necessary 2 gigs of memory, but you can try with three if you can afford it. gradle.properties. org.gradle.jvmargs=-Xmx3072m By default the Java max heap size is one

Recommends M-Wajeeh · 2017-06 · Stack Overflow · on “Android Studio Instant Run Issue”

This video really helped [this video] me reduce my build time. There is an excellent blog post related to this video: [LINK] I did following things to increase speed: Disable abi splits in development (You only need to do this if you are creating different apks based on CPU architecture): splits { abi { enable !project.hasProperty('devBuild') } } Disable png cruncher in development: android { if (project.hasProperty('devBuild')) { aaptOptions.cruncherEnabled = false } } Don't modify BuildConfig every time when you hit run: def gitSha = project.hasProperty('devBuild') ? "gitSha_devBuild" : 'git rev-parse --short HEAD'.execute([], project.rootDir).text.trim() def buildTime = project.hasProperty('de

Recommends Itamar Kerbel · 2018-10 · Stack Overflow · on “Proper use of 'implementation'”

First I encourage you to have a look here in the Google I/O 2017 [this video] . compile and implementation are not the same thing. compile lets the application access to all sub-dependencies that the sub-library has access to. This means that if MyLibrayOne depends on MyLibraryTwo and you need also access to the class from MyLibrarayTwo you'll have to direct gradle to expose the classes from MyLibrayTwo using the compile directive. If this is not needed then implementation is enough. I can only guess that your case is the former and so you'll need to keep using compile. Since compile is now deprecated use the api directive. They are the same. Also, have a look here in the gradle documentation [LI

Recommends Narendra_Nath · 2021-06 · Stack Overflow · on “Gradle build on Android Studio is taking around 40 min when project folder resides in Desktop Mac OS BigSur”

Do these things add org.gradle.caching=true add org.gradle.daemon=true If you have two variants of your app in the dev variant disable pngcrunching and disable it such that instead of searching for appropriate image it searches for a particular image itself(xxhdpi) in your dev block in gradle add these two lines splits.abi.enable=false and splits.density.enable=false Optimize your firebase crashalytics if you're using it. [Also see the google talk on improving Gradle builds][1] I improved my gradle time from 17 minutes to 9 following the above practices. Make sure you have offlinegradle button clicked in the gradle tab to the right of the screen. [1]: [this video]

Recommends LovinduLI · 2021-07 · Stack Overflow · on “Flutter run in vscode taking unexpectedly long time”

I am a windows user. My pc has a core i5-4200u(2 cores, 4 threads) with only 6GB ram. If you are trying to run the app in an android emulator or in an android device try this. Add following lines to the gradle.properties file found in your android folder in your project directory. org.gradle.daemon=true org.gradle.parallel=true org.gradle.configureondemand=true org.gradle.caching=true Checkout these 3 links for more information [LINK] [LINK] [this video] Earlier I had build times like 200s or more. But after enabling these features my build times got significantly lower. In the first run you won't notice a massive difference. But after that your build times will reduce massively. After doing all

Cites humazed · 2017-06 · Stack Overflow · on “What's the difference between "implementation", "api" and "compile" in Gradle?”

tl;dr Just replace: compile with implementation (if you don't need transitivity) or api (if you need transitivity) testCompile with testImplementation debugCompile with debugImplementation androidTestCompile with androidTestImplementation compileOnly is still valid. It was added in 3.0 to replace provided and not compile. ( provided introduced when Gradle didn't have a configuration name for that use-case and named it after Maven's provided scope.) It is one of the breaking changes coming with Android Gradle plugin 3.0 [LINK] that Google announced at IO17 [this video] . The compile configuration is now deprecated [this video] and should be replaced by implementation or api From the Gradle documentatio

Cites MatPag · 2017-06 · Stack Overflow · on “Gradle Implementation vs API configuration”

Gradle compile keyword was deprecated in favor of the api and implementation keywords to configure dependencies. Using api is the equivalent of using the deprecated compile , so if you replace all compile with api everything will works as always. To understand the implementation keyword consider the following example. EXAMPLE Suppose you have a library called MyLibrary that internally uses another library called InternalLibrary . Something like this: // 'InternalLibrary' module public class InternalLibrary { public static String giveMeAString(){ return "hello"; } } // 'MyLibrary' module public class MyLibrary { public String myString(){ return InternalLibrary.giveMeAString(); } } Suppose the

Cites arekolek · 2017-06 · Stack Overflow · on “Android - Only execute Gradle task on release build variant”

**Warning:** this may slow down your build. *One of the things we repeatedly see over and over again with people who complain about their slow build is the "doLast". "doLast" is bad, gradle cannot understand if your task is now incremental or not, because it doesn't know what you're doing in there.* [this video]

Cites Saurabh Thorat · 2017-08 · Stack Overflow · on “Gradle - Error Could not find method implementation() for arguments [com.android.support:appcompat-v7:26.0.0]”

Replace compile with implementation . compile was recently deprecated [this video] and replaced by implementation or api

Cites Prokash Sarkar · 2017-08 · Stack Overflow · on “java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/graphics/ColorUtils;”

I suspect the issue is related to using an older support library or by excluding the support-v4 module. Also, the compile configuration is now deprecated [this video] and should be replaced by implementation or api . Your final gradle configuration should look like this, implementation 'com.android.support:appcompat-v7:26.0.1' implementation 'com.android.support:recyclerview-v7:26.0.1' Finally, make sure to test once again with/without excluding the support-v4 module.