Android studio build slowed down after adding new libraries?

Viewed 2707

My application uses old architecture components. I want to move to new android architecture components.

For this purpose I added room related dependencies in the beginning, after that build was normal.

But when I tried adding dependencies for Lyfecycles, LiveData and ViewModel, as mentioned here.

Application build process slowed down considerably, 5 mins and more time is required to build apk.

Following dependecies added in app's build.gradle :

    compile "android.arch.lifecycle:runtime:1.0.0-alpha5"
    compile "android.arch.lifecycle:extensions:1.0.0-alpha5"
    annotationProcessor "android.arch.lifecycle:compiler:1.0.0-alpha5"

Also I have to enable jack for Java 8 compatibility, as follows :

defaultConfig {
........
        jackOptions {
            enabled true
        }
    }

After adding all these componets build process has slowed down considerably. I tried making some custom VM option changes for some parameters by going to Help -> Edit custom VM options

-Xmx5120m

I set it to almost 5 GBs but nothing worked for me. My machine has enough hardware I believe. ( 8 GB RAM, Windows 10, 1TB HDD, AMD A8)

My application makes use of many google services, like Gmail API, Firebase APIs, some other libraries did I exhausted 64K reference limit ? But I have already enabled the multidexing as mentioned here.

Did this happened because of new architecture components or something else ? How do I make build process faster ?

Update :

One of the answer below by Budius suggested a script which will show timings taken by each build process, I executed it in my application here are the findings :

BUILD SUCCESSFUL

Total time: 18 mins 28.44 secs
Task timings:
    480ms  :app:mergeDebugResources
   2516ms  :app:processDebugResources
 487725ms  :app:transformClassesWithPreJackPackagedLibrariesForDebug
  29213ms  :app:transformClassesWithPreJackRuntimeLibrariesForDebug
    752ms  :app:transformResourcesWithMergeJavaResForDebug
 556894ms  :app:transformJackWithJackForDebug
   5184ms  :app:transformNativeLibsWithMergeJniLibsForDebug
  17524ms  :app:packageDebug

Most of the timings are taken by Jack.

I tried the canary version suggested in below answer by Bryan following is output of the timing taken for build process :

BUILD SUCCESSFUL in 6m 11s
42 actionable tasks: 33 executed, 9 up-to-date
Task timings:
    608ms  :app:preDebugBuild
    350ms  :app:mergeDebugResources
    394ms  :app:processDebugManifest
   2543ms  :app:processDebugResources
   9410ms  :app:javaPreCompileDebug
  46585ms  :app:compileDebugJavaWithJavac
    262ms  :app:compileDebugShaders
    395ms  :app:mergeDebugAssets
   5835ms  :app:packageInstantRunResourcesDebug
  98922ms  :app:transformClassesWithDesugarForDebug
    334ms  :app:transformClassesWithExtractJarsForDebug
   7765ms  :app:transformClassesWithInstantRunVerifierForDebug
  23117ms  :app:transformNativeLibsWithMergeJniLibsForDebug
  10128ms  :app:transformResourcesWithMergeJavaResForDebug
  16565ms  :app:transformClassesWithInstantRunForDebug
  11825ms  :app:transformClassesWithInstantRunSlicerForDebug
  84703ms  :app:transformClassesWithDexBuilderForDebug
  17061ms  :app:transformDexArchiveWithDexMergerForDebug
   1706ms  :app:transformDexWithInstantRunDependenciesApkForDebug
   9770ms  :app:transformDexWithInstantRunSlicesApkForDebug
  10571ms  :app:packageDebug
   1387ms  :app:buildInfoGeneratorDebug

So I removed jack & switched to this canary version, build is faster than previous for sure but still slow for use.

7 Answers
Related