SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
How to improve Gradle build
speed
Fate Chang
2016/05/18
Google I/O Extended 2016 Taipei
About me
● Fate Chang
● Leopard Mobile
● Android developer
● Focus on architecture and performance
● 1000th member of GCPUG.TW
● fb.me/fate.tw
● +FateChang
When build is so slow...
It’s easily distracted.
Why build so slow
● Slow computer
● Not enough memory
● Complicate project
● Old version tools
● Wrong setting
● Slow network
● ...
We got a chance to try it
● Try our Gradle configuration on Mac Pro
● Our project CMSecurity release build time around 2 mins.
● Can we make it faster?
● At this moment Gradle daemon is all I know
Let’s Do It!
Step by step
Profiling
● Example project : https://github.com/google/iosched
● Checkout from github
● Setup baseline
○ $ ./gradlew assembleDebug --dry-run
○ Run above command several time
○ Get average time
○ Total time: 6.371 secs
--dry-run
● Runs the build with all task actions disabled
○ Sometimes you are interested in which tasks are executed in which order
for a given set of tasks specified on the command line, but you don't want
the tasks to be executed.
--profile
● $ ./gradlew assembleDebug --dry-run --profile
○ --profile parameter will generate profile report page
○ Total build time : 7.809s
● $ open build/reports/profile/profile-2016-05-18-15-18-07.html
--configure-on-demand
● $ ./gradlew assembleDebug --dry-run --profile --configure-
on-demand
● Total build time : 6.704s
--daemon
● $ ./gradlew assembleDebug --dry-run --profile --configure-
on-demand --daemon
● Total build time : 2.663s
Notes of using Gradle daemon
DON’T USE GRADLE DAEMON ON CI.
When should I not use the Gradle Daemon
https://docs.gradle.org/current/userguide/gradle_daemon.
html#when_should_i_not_use_the_gradle_daemon
How does the Gradle Daemon make builds faster
https://docs.gradle.org/current/userguide/gradle_daemon.html#N1056F
--parallel
● $ ./gradlew assembleDebug --dry-run --profile --configure-
on-demand --daemon --parallel
● Total build time : 2.382s
The improvement
7.832s -> 2.382s
Other useful Gradle parameter
● --info
○ Output more log during build.
● --offline
○ Set Gradle to operate without accessing network
resources.
○ Note : should remove --offline to check consistency
when library upgraded.
● More docs : https://docs.gradle.
org/current/userguide/gradle_command_line.html
How to add parameters in Android
Studio
Optimizing Multidex Development Builds
Ref:https://developer.android.com/studio/build/multidex.
html#dev-build
Multidex enabled sample project result
Scenario: Clean project and rebuild.
$ ./gradlew clean
$ ./gradlew assembleXxxxx --configure-on-demand --daemon --parallel --offline --
info
minSdkVersion 14
Total time: 63.168s secs
minSdkVersion 21
Total time: 52.029 secs
That’s All?
Most recent changes
● Newer Gradle version performance is better
○ In 2.13 release notes, measured up to 25% improvements
○ Ref : https://docs.gradle.org/2.13/release-notes
● Faster Android Studio Builds with Dex In Process
○ Enabled in Android Studio 2.1
○ Modify gradle.properties
○ org.gradle.jvmargs=-Xmx2048m
○ Ref : https://medium.com/google-developers/faster-android-studio-builds-
with-dex-in-process-5988ed8aa37e
Update Gradle Android Plugin Version.
If you upgrade Android Studio to 2.1.x recently,
you’ll see this dialog
Note: Update Gradle plugin up to 2.x, Intstant run is default
enabled
If yout don’t update in previous dialog, you can update
configuration manually.
Update Gradle Android Plugin Version Manually
In Android Studio
Android Studio 2.1 new feature
● Dex In Process
● This can dramatically increase the speed of
full clean build.
● Should update Android plugin version to 2.1.0
as well.
Make dex in process running
If you add dexOptions in build.gradle
You may see this message.
Dex in process not working log
Build with --info parameter
If you see Dexing out-of-process log, it’s not
working.
Let’s add setting to gradle.properties
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx5120m
Don’t commit these config to version control.
or yout can use -Dorg.gradle.jvmargs=-Xmx5120m parameter in command
line
Still not working?
Reduce javaMaxHeapSize
Build with --info parameter
If you see Dexing in-process log, you’re all set.
Speed Up In CMSecurity
Build time from 2 mins 20s to less than 1 min.
(Tested on MBPR 15” mid 2012 16GB Ram)
Slow in Android Studio but fast in
command line?
Try disable Instant Run.
Summary
● Faster CPU is better!
● Use latest gradle version (2.13)
● Use latest android plugin (2.1.0)
● Adjust setting according to your memory
● Disable Instant Run, unless you really need it.
One setting won’t fit all, you need to try the combination for
best result
Note : Use retrolambda will cause rebuild each time.
References
● 6 tips to speed up your Gradle build
○ https://medium.com/@shelajev/6-tips-to-speed-up-your-gradle-build-
3d98791d3df9
● Faster Android Studio Builds with Dex In
Process
○ https://medium.com/google-developers/faster-android-studio-builds-with-
dex-in-process-5988ed8aa37e

Contenu connexe

Tendances

Grunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierGrunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierErick Brito
 
Grunt js and WordPress
Grunt js and WordPressGrunt js and WordPress
Grunt js and WordPressWP Australia
 
Automating WordPress Plugin Development with Gulp
Automating WordPress Plugin Development with GulpAutomating WordPress Plugin Development with Gulp
Automating WordPress Plugin Development with GulpMike Hale
 
Gradle build automation tool
Gradle   build automation toolGradle   build automation tool
Gradle build automation toolIoan Eugen Stan
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deckJames Ford
 
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47Bartosz Kosarzycki
 
Devenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.jsDevenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.jsRémy Savard
 
Java and Container - Make it Awesome !
Java and Container - Make it Awesome !Java and Container - Make it Awesome !
Java and Container - Make it Awesome !Dinakar Guniguntala
 
World is changed. i feel it in the front end
World is changed. i feel it in the front endWorld is changed. i feel it in the front end
World is changed. i feel it in the front endAndriy Yun
 
Development tools at Base
Development tools at BaseDevelopment tools at Base
Development tools at BaseDominik Kapusta
 
Gulp: Your Build Process Will Thank You
Gulp: Your Build Process Will Thank YouGulp: Your Build Process Will Thank You
Gulp: Your Build Process Will Thank YouRadWorks
 
[GREE Tech Talk #08] You Don't Know WebGL
[GREE Tech Talk #08] You Don't Know WebGL[GREE Tech Talk #08] You Don't Know WebGL
[GREE Tech Talk #08] You Don't Know WebGLgree_tech
 

Tendances (19)

Grunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End TierGrunt Continuous Development of the Front End Tier
Grunt Continuous Development of the Front End Tier
 
Grunt js and WordPress
Grunt js and WordPressGrunt js and WordPress
Grunt js and WordPress
 
Automating WordPress Plugin Development with Gulp
Automating WordPress Plugin Development with GulpAutomating WordPress Plugin Development with Gulp
Automating WordPress Plugin Development with Gulp
 
Gradle build automation tool
Gradle   build automation toolGradle   build automation tool
Gradle build automation tool
 
Grunt training deck
Grunt training deckGrunt training deck
Grunt training deck
 
JavaScript Task Runners - Gulp & Grunt
JavaScript Task Runners - Gulp & GruntJavaScript Task Runners - Gulp & Grunt
JavaScript Task Runners - Gulp & Grunt
 
Grunt
GruntGrunt
Grunt
 
Gradle : An introduction
Gradle : An introduction Gradle : An introduction
Gradle : An introduction
 
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47Android - Gradle build optimisation  3d83f31339d239abcc55f869e5f30348?s=47
Android - Gradle build optimisation 3d83f31339d239abcc55f869e5f30348?s=47
 
Gradle Introduction
Gradle IntroductionGradle Introduction
Gradle Introduction
 
Devenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.jsDevenez le plus heureux des Front-end avec Gulp.js
Devenez le plus heureux des Front-end avec Gulp.js
 
Java and Container - Make it Awesome !
Java and Container - Make it Awesome !Java and Container - Make it Awesome !
Java and Container - Make it Awesome !
 
Зоопарк React-у
Зоопарк React-уЗоопарк React-у
Зоопарк React-у
 
OpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with GradleOpenCms Days 2012 - Developing OpenCms with Gradle
OpenCms Days 2012 - Developing OpenCms with Gradle
 
World is changed. i feel it in the front end
World is changed. i feel it in the front endWorld is changed. i feel it in the front end
World is changed. i feel it in the front end
 
Development tools at Base
Development tools at BaseDevelopment tools at Base
Development tools at Base
 
Gulp: Your Build Process Will Thank You
Gulp: Your Build Process Will Thank YouGulp: Your Build Process Will Thank You
Gulp: Your Build Process Will Thank You
 
[GREE Tech Talk #08] You Don't Know WebGL
[GREE Tech Talk #08] You Don't Know WebGL[GREE Tech Talk #08] You Don't Know WebGL
[GREE Tech Talk #08] You Don't Know WebGL
 
Gulp: Task Runner
Gulp: Task RunnerGulp: Task Runner
Gulp: Task Runner
 

Similaire à How to improve gradle build speed

Decrease build time and application size
Decrease build time and application sizeDecrease build time and application size
Decrease build time and application sizeKeval Patel
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation ToolIzzet Mustafaiev
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Jared Burrows
 
Michal Havryluk: How To Speed Up Android Gradle Builds
Michal Havryluk: How To Speed Up Android Gradle BuildsMichal Havryluk: How To Speed Up Android Gradle Builds
Michal Havryluk: How To Speed Up Android Gradle Buildsmdevtalk
 
Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Eric Wendelin
 
ContainerDayVietnam2016: Django Development with Docker
ContainerDayVietnam2016: Django Development with DockerContainerDayVietnam2016: Django Development with Docker
ContainerDayVietnam2016: Django Development with DockerDocker-Hanoi
 
Grunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationDavid Amend
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016vodqasg
 
Automate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.jsAutomate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.jsJosh Lee
 
Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021Martin Anderson-Clutz
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal DevelopmentChris Tankersley
 
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow MeetupWhat's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow MeetupKaxil Naik
 
Google Cloud Platform Special Training
Google Cloud Platform Special TrainingGoogle Cloud Platform Special Training
Google Cloud Platform Special TrainingSimon Su
 
Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Opersys inc.
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master BuilderPhilip Norton
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overviewKevin He
 

Similaire à How to improve gradle build speed (20)

Decrease build time and application size
Decrease build time and application sizeDecrease build time and application size
Decrease build time and application size
 
Gradle - the Enterprise Automation Tool
Gradle  - the Enterprise Automation ToolGradle  - the Enterprise Automation Tool
Gradle - the Enterprise Automation Tool
 
Gradle
GradleGradle
Gradle
 
Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)Make Your Build Great Again (DroidConSF 2017)
Make Your Build Great Again (DroidConSF 2017)
 
Michal Havryluk: How To Speed Up Android Gradle Builds
Michal Havryluk: How To Speed Up Android Gradle BuildsMichal Havryluk: How To Speed Up Android Gradle Builds
Michal Havryluk: How To Speed Up Android Gradle Builds
 
Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!Gradle 3.0: Unleash the Daemon!
Gradle 3.0: Unleash the Daemon!
 
ContainerDayVietnam2016: Django Development with Docker
ContainerDayVietnam2016: Django Development with DockerContainerDayVietnam2016: Django Development with Docker
ContainerDayVietnam2016: Django Development with Docker
 
Grunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous IntegrationGrunt.js and Yeoman, Continous Integration
Grunt.js and Yeoman, Continous Integration
 
Kranthi kumar implement_ci_cd_my_notes
Kranthi kumar implement_ci_cd_my_notesKranthi kumar implement_ci_cd_my_notes
Kranthi kumar implement_ci_cd_my_notes
 
Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016Serenity BDD Workshop - 9th March 2016
Serenity BDD Workshop - 9th March 2016
 
Gradle - Build System
Gradle - Build SystemGradle - Build System
Gradle - Build System
 
Automate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.jsAutomate your WordPress Workflow with Grunt.js
Automate your WordPress Workflow with Grunt.js
 
Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021Configuration Kits - DrupalCamp NYC 2021
Configuration Kits - DrupalCamp NYC 2021
 
Modernize Your Drupal Development
Modernize Your Drupal DevelopmentModernize Your Drupal Development
Modernize Your Drupal Development
 
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow MeetupWhat's coming in Airflow 2.0? - NYC Apache Airflow Meetup
What's coming in Airflow 2.0? - NYC Apache Airflow Meetup
 
Google Cloud Platform Special Training
Google Cloud Platform Special TrainingGoogle Cloud Platform Special Training
Google Cloud Platform Special Training
 
Drupal Best Practices
Drupal Best PracticesDrupal Best Practices
Drupal Best Practices
 
Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013Android Platform Debugging and Development at ELCE 2013
Android Platform Debugging and Development at ELCE 2013
 
Becoming A Drupal Master Builder
Becoming A Drupal Master BuilderBecoming A Drupal Master Builder
Becoming A Drupal Master Builder
 
Android gradle-build-system-overview
Android gradle-build-system-overviewAndroid gradle-build-system-overview
Android gradle-build-system-overview
 

How to improve gradle build speed

  • 1. How to improve Gradle build speed Fate Chang 2016/05/18 Google I/O Extended 2016 Taipei
  • 2. About me ● Fate Chang ● Leopard Mobile ● Android developer ● Focus on architecture and performance ● 1000th member of GCPUG.TW ● fb.me/fate.tw ● +FateChang
  • 3. When build is so slow... It’s easily distracted.
  • 4. Why build so slow ● Slow computer ● Not enough memory ● Complicate project ● Old version tools ● Wrong setting ● Slow network ● ...
  • 5. We got a chance to try it ● Try our Gradle configuration on Mac Pro ● Our project CMSecurity release build time around 2 mins. ● Can we make it faster? ● At this moment Gradle daemon is all I know
  • 7. Profiling ● Example project : https://github.com/google/iosched ● Checkout from github ● Setup baseline ○ $ ./gradlew assembleDebug --dry-run ○ Run above command several time ○ Get average time ○ Total time: 6.371 secs
  • 8. --dry-run ● Runs the build with all task actions disabled ○ Sometimes you are interested in which tasks are executed in which order for a given set of tasks specified on the command line, but you don't want the tasks to be executed.
  • 9. --profile ● $ ./gradlew assembleDebug --dry-run --profile ○ --profile parameter will generate profile report page ○ Total build time : 7.809s ● $ open build/reports/profile/profile-2016-05-18-15-18-07.html
  • 10. --configure-on-demand ● $ ./gradlew assembleDebug --dry-run --profile --configure- on-demand ● Total build time : 6.704s
  • 11. --daemon ● $ ./gradlew assembleDebug --dry-run --profile --configure- on-demand --daemon ● Total build time : 2.663s
  • 12. Notes of using Gradle daemon DON’T USE GRADLE DAEMON ON CI. When should I not use the Gradle Daemon https://docs.gradle.org/current/userguide/gradle_daemon. html#when_should_i_not_use_the_gradle_daemon How does the Gradle Daemon make builds faster https://docs.gradle.org/current/userguide/gradle_daemon.html#N1056F
  • 13. --parallel ● $ ./gradlew assembleDebug --dry-run --profile --configure- on-demand --daemon --parallel ● Total build time : 2.382s
  • 15. Other useful Gradle parameter ● --info ○ Output more log during build. ● --offline ○ Set Gradle to operate without accessing network resources. ○ Note : should remove --offline to check consistency when library upgraded. ● More docs : https://docs.gradle. org/current/userguide/gradle_command_line.html
  • 16. How to add parameters in Android Studio
  • 17. Optimizing Multidex Development Builds Ref:https://developer.android.com/studio/build/multidex. html#dev-build
  • 18. Multidex enabled sample project result Scenario: Clean project and rebuild. $ ./gradlew clean $ ./gradlew assembleXxxxx --configure-on-demand --daemon --parallel --offline -- info minSdkVersion 14 Total time: 63.168s secs minSdkVersion 21 Total time: 52.029 secs
  • 20. Most recent changes ● Newer Gradle version performance is better ○ In 2.13 release notes, measured up to 25% improvements ○ Ref : https://docs.gradle.org/2.13/release-notes ● Faster Android Studio Builds with Dex In Process ○ Enabled in Android Studio 2.1 ○ Modify gradle.properties ○ org.gradle.jvmargs=-Xmx2048m ○ Ref : https://medium.com/google-developers/faster-android-studio-builds- with-dex-in-process-5988ed8aa37e
  • 21. Update Gradle Android Plugin Version. If you upgrade Android Studio to 2.1.x recently, you’ll see this dialog Note: Update Gradle plugin up to 2.x, Intstant run is default enabled
  • 22. If yout don’t update in previous dialog, you can update configuration manually. Update Gradle Android Plugin Version Manually In Android Studio
  • 23. Android Studio 2.1 new feature ● Dex In Process ● This can dramatically increase the speed of full clean build. ● Should update Android plugin version to 2.1.0 as well.
  • 24. Make dex in process running If you add dexOptions in build.gradle You may see this message.
  • 25. Dex in process not working log Build with --info parameter If you see Dexing out-of-process log, it’s not working.
  • 26. Let’s add setting to gradle.properties org.gradle.daemon=true org.gradle.configureondemand=true org.gradle.parallel=true org.gradle.jvmargs=-Xmx5120m Don’t commit these config to version control. or yout can use -Dorg.gradle.jvmargs=-Xmx5120m parameter in command line
  • 27. Still not working? Reduce javaMaxHeapSize Build with --info parameter If you see Dexing in-process log, you’re all set.
  • 28. Speed Up In CMSecurity Build time from 2 mins 20s to less than 1 min. (Tested on MBPR 15” mid 2012 16GB Ram)
  • 29. Slow in Android Studio but fast in command line? Try disable Instant Run.
  • 30. Summary ● Faster CPU is better! ● Use latest gradle version (2.13) ● Use latest android plugin (2.1.0) ● Adjust setting according to your memory ● Disable Instant Run, unless you really need it. One setting won’t fit all, you need to try the combination for best result Note : Use retrolambda will cause rebuild each time.
  • 31. References ● 6 tips to speed up your Gradle build ○ https://medium.com/@shelajev/6-tips-to-speed-up-your-gradle-build- 3d98791d3df9 ● Faster Android Studio Builds with Dex In Process ○ https://medium.com/google-developers/faster-android-studio-builds-with- dex-in-process-5988ed8aa37e