Effective Gradle Scripts for Android Projects

Effective Gradle Scripts for Android Projects

Writing better gradle scripts for large and complex android apps. Captured best practices applied in revamping gradle scripts for Dailyhunt app which has 35 modules, few custom tasks and lots of dependencies. Intention is to capture not just speed boosters, but solutions to keep scripts files simpler, smart and well maintained.

A840d50ff8fdfeefe6d6bd98b4f18873?s=128

Arun Babu A S P

November 10, 2016
Tweet

Transcript

  1. None
  2. Image Processing Library

  3. Image Processing Library Supports GIF animations

  4. Image Processing Library Supports GIF animations Allows lot of configuration

  5. Image Processing Library Supports GIF animations Allows lot of configuration

    Maintained by Googlers
  6. Image Processing Library Supports GIF animations Allows lot of configuration

    Maintained by Googlers Open source @Github
  7. None
  8. None
  9. None
  10. E F F E C T I V E GRADLE

    SCRIPTS FOR ANDROID PROJECTS
  11. None
  12. https://github.com/babuasp2003/glide/tree/better_scripts

  13. Item 1: Break your code!

  14. 1 module 1 package 1 java file

  15. 1 module 1 package few java files

  16. 1 module few packages more java files

  17. few modules lot more packages many more java files

  18. lot of modules lot more packages countless java files

  19. Module ownership is a challenge

  20. Module ownership is a challenge Code reviews became difficult

  21. Module ownership is a challenge Code reviews became difficult Gradle

    takes forever to build
  22. Create multiple smaller projects

  23. Create multiple smaller projects Upload module aars to local maven

  24. Create multiple smaller projects Upload module aars to local maven

    Reference dependencies remotely
  25. Glide project

  26. Only flickr stuff

  27. Everything else

  28. End structure

  29. Item 2: Composite builds

  30. None
  31. A composite build is simply a build that includes other

    builds.
  32. A composite build is simply a build that includes other

    builds. settings.gradle
  33. + Compose multiple random builds

  34. + Compose multiple random builds + Will be useful for

    large projects
  35. + Compose multiple random builds + Will be useful for

    large projects - Only from Gradle version (3.x)
  36. + Compose multiple random builds + Will be useful for

    large projects - Only from Gradle version (3.x) - Not yet in Android Studio :(
  37. Item 3: Declare Dependencies

  38. Good old direct entries

  39. Setting versions in root build.gradle

  40. dependency.gradle build.gradle

  41. + Enable single place ver. update

  42. + Enable single place ver. update + Can use no-op

    lib for debugging
  43. + Enable single place ver. update + Can use no-op

    lib for debugging - Lib updates will not show up auto
  44. Item 4: Secure passwords

  45. Teams might work from diff sites

  46. Teams might work from diff sites There could be freelancers

  47. Teams might work from diff sites There could be freelancers

    Some might return from US
  48. Load password from env. variables

  49. Item 5: (Flavor)Dimension

  50. None
  51. + When new config needed (less)

  52. + When new config needed (less) + Can inherit basic

    properties
  53. + When new config needed (less) + Can inherit basic

    properties - Can increase build time
  54. Exclude redundant combinations

  55. Removed!

  56. Item 6: Build Performance

  57. Measure!

  58. --profile

  59. - Does not work for regular info - Some devs

    might have slow laptop
  60. Build scan

  61. Optimize it...

  62. Dex options (ci vs dev)

  63. Grade Properties (ci vs dev)

  64. E F F E C T I V E GRADLE

    SCRIPTS FOR ANDROID PROJECTS
  65. Item 7: Don’t use Gradle

  66. Item 7: Buck build for Dev

  67. OkBuck

  68. + Gradle plugin to gen. Buck rules

  69. + Gradle plugin to gen. Buck rules + Buck wrapper

    based on Gradle
  70. + Gradle plugin to gen. Buck rules + Buck wrapper

    based on Gradle + Many times faster than Gradle
  71. + Gradle plugin to gen. Buck rules + Buck wrapper

    based on Gradle + Many times faster than Gradle - Not supported by Google
  72. as valuable as

  73. THANKS Arun Babu A S P https://yourstory.com/2016/09/arun-babu-story/