Performance tweaks for Android Studio and Gradle by Samuel Dionne

Performance tweaks for Android Studio and Gradle by Samuel Dionne

Android Studio is an awesome tool for Android development, but it may be sluggish at times. We’ll explore some of the ways you can tweak it to make it faster. AS is not the only culprit when it comes to performance. Gradle builds are sometimes, nay, always slow but there are some parameters we can use to improve its performance. When everything else fails, raw power does it.

https://gdgmontreal.com/2020/02/11/february-2nd-meetup/

studio64.vmoptions
-Xms3g
-Xmx3g
-XX:NewRatio=3
-XX:ReservedCodeCacheSize=480m
-XX:MetaspaceSize=512m
-Xss16m
-XX:+UseCompressedOops
-Dfile.encoding=UTF
-Dawt.useSystemAAFontSettings=on
-Dsun.java2d.noddraw=false
-XX:+UseConcMarkSweepGC
-XX:SoftRefLRUPolicyMSPerMB=50
-server

gradle.properties
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2560M -Dkotlin.daemon.jvm.options="-Xmx2560M" -Dfile.encoding=UTF-8
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.caching=true
kapt.incremental.apt=true
kapt.use.worker.api=true
kapt.include.compile.classpath=false

1b77dd441f657f5aefb3e21283b252e6?s=128

GDG Montreal

February 26, 2020
Tweet

Transcript

  1. Performance tweaks for AS and Gradle 12 + 1 tips

    to make your life better
  2. Samuel Dionne Transit Android development for 10 years Started on

    Eclipse AS + Gradle is still painful
  3. 7 Gradle tips 5 Android Studio tips

  4. 7 Gradle tips 5 Android Studio tips

  5. 1. Disable Plugins File > Settings > Plugins

  6. 2. Custom VM Options Help > Edit Custom VM Options

  7. Here is the content of my studio64.vmoptions # custom Android

    Studio VM options, see https://developer.android.com/studio/intro/studio-config.html -Xms3g -Xmx3g -XX:NewRatio=3 -XX:ReservedCodeCacheSize=480m -XX:MetaspaceSize=512m -Xss16m -XX:+UseCompressedOops -Dfile.encoding=UTF -Dawt.useSystemAAFontSettings=on -Dsun.java2d.noddraw=false -XX:+UseConcMarkSweepGC -XX:SoftRefLRUPolicyMSPerMB=50 -server
  8. 3. No dynamic version in gradle dependencies

  9. 4. Experiment settings File > Settings > Experimental

  10. 5. Memory indicator File > Settings > Appearance

  11. 7 Gradle tips 5 Android Studio tips

  12. 1. Disable PNG Cruncher buildTypes.debug.crunchPngs

  13. 1. Disable PNG Cruncher File > Settings > Plugins Better

    Yet! Convert all images to WebP*
  14. 2. Disable Crashlytics Build Id ext.alwaysUpdateBuildId

  15. 2. Disable Crashlytics BuildId build.gradle Better Yet! Disable Crashlytics completely

    ext.enableCrashlytics
  16. 3. Enable daemon org.gradle.daemon

  17. 4. Parallel build org.gradle.parallel

  18. 5. Caching* org.gradle.caching

  19. 6. Memory params org.gradle.jvmargs

  20. Here is the content of my gradle.properties android.enableJetifier=true android.useAndroidX=true org.gradle.jvmargs=-Xmx2560M

    -Dkotlin.daemon.jvm.options="-Xmx2560M" -Dfile.encoding=UTF-8 org.gradle.daemon=true org.gradle.parallel=true org.gradle.caching=true kapt.incremental.apt=true kapt.use.worker.api=true kapt.include.compile.classpath=false
  21. 7. Offline mode File > Settings > Build > Gradle

  22. 5 Android Studio tips 7 Gradle tips

  23. 5 Android Studio tips 7 Gradle tips Please make it

    even FASTER
  24. 5 Android Studio tips 7 Gradle tips 50k Mac Pro

  25. 5 Android Studio tips 7 Gradle tips Steal CPU and

    Memory 50k Mac Pro
  26. 5 Android Studio tips 7 Gradle tips 50k Mac Pro

    Steal CPU and Memory Rent a Big Server
  27. 1. Copy our local files to the server

  28. 1. Copy our local files to the server 2. Run

    gradle build on the server
  29. 1. Copy our local files to the server 7. Offline

    mode File > Settings > Build > Gradle 3. Copy the results files locally
  30. Gradle plugin Mirakle github.com/Instamotor-Labs/mirakle

  31. - 3x faster incremental build - 5x faster full build

    - Shared C++ cache - Shared Gradle build cache (coming soon) - 6 person team == lot of minutes saved
  32. Thank you for listening Questions?