Kotlin 讓人既愛有恨之編譯速度優(yōu)化

Kotlin 讓人既愛有恨之編譯速度優(yōu)化

寫kotlin很久了温峭,一直以來都不太滿意kotlin的編譯速度,特別是項目中大量使用kapt 。但是也能忍受却桶。但自從我的電腦讓我玩壞了之后碱呼。編譯速度一度讓我懷疑人生砍艾,總感覺星哥順走了我的內(nèi)存條∥【伲可惜我這里監(jiān)控盲區(qū)??脆荷,廢話不多說讓我們看看具體步驟
優(yōu)化前和優(yōu)化后速度對

優(yōu)化之前構建總耗時:241909ms·
構建時間:2021-05-14 15:55:48
開始構建----------------------
[:clean]:25ms
[:component:Chatjoy:clean]:4952ms
[:component:Chatjoy:picture_library:clean]:355ms
[:component:Chatjoy:sharelibrary:clean]:88ms
[:component:Chatjoy:ucrop:clean]:155ms
[:component:Chatjoy:util_library:clean]:107ms
[:component:Chatjoy:util_library:preBuild]:0ms
[:component:Chatjoy:util_library:preDebugBuild]:0ms
[:component:Chatjoy:util_library:compileDebugAidl]:15ms
[:component:Chatjoy:util_library:mergeDebugJniLibFolders]:30ms
[:component:Chatjoy:util_library:mergeDebugNativeLibs]:1ms
[:component:Chatjoy:util_library:stripDebugDebugSymbols]:1ms
[:component:Chatjoy:util_library:compileDebugRenderscript]:4ms
[:component:Chatjoy:util_library:generateDebugBuildConfig]:18ms
[:component:Chatjoy:util_library:generateDebugResValues]:2ms
[:component:Chatjoy:util_library:generateDebugResources]:0ms
[:component:Chatjoy:util_library:packageDebugResources]:170ms
[:component:Chatjoy:util_library:copyDebugJniLibsProjectAndLocalJars]:14ms
[:component:Chatjoy:util_library:mergeDebugShaders]:12ms
[:component:Chatjoy:util_library:compileDebugShaders]:2ms
[:component:Chatjoy:util_library:generateDebugAssets]:0ms
[:component:Chatjoy:util_library:packageDebugAssets]:15ms
[:component:Chatjoy:util_library:packageDebugRenderscript]:1ms
[:component:Chatjoy:util_library:processDebugJavaRes]:1ms
[:component:Chatjoy:util_library:prepareLintJarForPublish]:4ms
[:component:Chatjoy:ucrop:preBuild]:0ms
[:component:Chatjoy:ucrop:preDebugBuild]:0ms
[:component:Chatjoy:ucrop:compileDebugAidl]:1ms
[:component:Chatjoy:ucrop:mergeDebugJniLibFolders]:12ms
[:component:Chatjoy:ucrop:mergeDebugNativeLibs]:1ms
[:component:Chatjoy:ucrop:stripDebugDebugSymbols]:0ms
[:component:Chatjoy:util_library:writeDebugAarMetadata]:8ms
[:component:Chatjoy:ucrop:compileDebugRenderscript]:2ms
[:component:Chatjoy:ucrop:generateDebugBuildConfig]:14ms
[:component:Chatjoy:ucrop:generateDebugResValues]:3ms
[:component:Chatjoy:ucrop:generateDebugResources]:0ms
[:component:Chatjoy:ucrop:packageDebugResources]:451ms
[:component:Chatjoy:ucrop:copyDebugJniLibsProjectAndLocalJars]:6ms
[:component:Chatjoy:ucrop:mergeDebugShaders]:10ms
[:component:Chatjoy:ucrop:compileDebugShaders]:1ms
[:component:Chatjoy:ucrop:generateDebugAssets]:0ms
[:component:Chatjoy:ucrop:packageDebugAssets]:9ms
[:component:Chatjoy:ucrop:packageDebugRenderscript]:1ms
[:component:Chatjoy:ucrop:processDebugJavaRes]:1ms
[:component:Chatjoy:ucrop:parseDebugLocalResources]:14ms
[:component:Chatjoy:sharelibrary:preBuild]:0ms
[:component:Chatjoy:sharelibrary:preDebugBuild]:0ms
[:component:Chatjoy:sharelibrary:compileDebugAidl]:1ms
[:component:Chatjoy:sharelibrary:mergeDebugJniLibFolders]:44ms
[:component:Chatjoy:sharelibrary:mergeDebugNativeLibs]:1ms
[:component:Chatjoy:sharelibrary:stripDebugDebugSymbols]:0ms
[:component:Chatjoy:ucrop:writeDebugAarMetadata]:11ms
[:component:Chatjoy:sharelibrary:compileDebugRenderscript]:1ms
[:component:Chatjoy:sharelibrary:generateDebugBuildConfig]:12ms
[:component:Chatjoy:sharelibrary:generateDebugResValues]:2ms
[:component:Chatjoy:sharelibrary:generateDebugResources]:0ms
[:component:Chatjoy:sharelibrary:packageDebugResources]:21ms
[:component:Chatjoy:ucrop:mergeDebugJavaResource]:7ms
[:component:Chatjoy:sharelibrary:parseDebugLocalResources]:10ms
[:component:Chatjoy:sharelibrary:mergeDebugShaders]:18ms
[:component:Chatjoy:sharelibrary:compileDebugShaders]:1ms
[:component:Chatjoy:sharelibrary:generateDebugAssets]:0ms
[:component:Chatjoy:sharelibrary:packageDebugAssets]:12ms
[:component:Chatjoy:sharelibrary:packageDebugRenderscript]:1ms
[:component:Chatjoy:sharelibrary:processDebugJavaRes]:0ms
[:component:Chatjoy:picture_library:preBuild]:0ms
[:component:Chatjoy:sharelibrary:prepareLintJarForPublish]:1ms
[:component:Chatjoy:picture_library:preDebugBuild]:0ms
[:component:Chatjoy:picture_library:compileDebugAidl]:1ms
[:component:Chatjoy:picture_library:mergeDebugJniLibFolders]:13ms
[:component:Chatjoy:picture_library:mergeDebugNativeLibs]:2ms
[:component:Chatjoy:picture_library:stripDebugDebugSymbols]:1ms
[:component:Chatjoy:sharelibrary:processDebugManifest]:50ms
[:component:Chatjoy:ucrop:processDebugManifest]:338ms
[:component:Chatjoy:picture_library:copyDebugJniLibsProjectAndLocalJars]:79ms
[:component:Chatjoy:picture_library:compileDebugRenderscript]:1ms
[:component:Chatjoy:picture_library:generateDebugBuildConfig]:18ms
[:component:Chatjoy:picture_library:generateDebugResValues]:3ms
[:component:Chatjoy:picture_library:generateDebugResources]:1ms
[:component:Chatjoy:picture_library:packageDebugResources]:720ms
[:component:Chatjoy:ucrop:javaPreCompileDebug]:5ms
[:component:Chatjoy:sharelibrary:javaPreCompileDebug]:4ms
[:component:Chatjoy:picture_library:mergeDebugShaders]:16ms
[:component:Chatjoy:picture_library:compileDebugShaders]:1ms
[:component:Chatjoy:picture_library:generateDebugAssets]:0ms
[:component:Chatjoy:picture_library:packageDebugAssets]:9ms
[:component:Chatjoy:picture_library:processDebugManifest]:39ms
[:component:Chatjoy:picture_library:packageDebugRenderscript]:1ms
[:component:Chatjoy:picture_library:processDebugJavaRes]:1ms
[:component:Chatjoy:util_library:processDebugManifest]:31ms
[:component:Chatjoy:picture_library:mergeDebugJavaResource]:3ms
[:component:Chatjoy:preBuild]:0ms
[:component:Chatjoy:preChatjoyLocalDevelopDebugBuild]:0ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugAidl]:1ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugRenderscript]:1ms
[:component:Chatjoy:sharelibrary:generateDebugRFile]:419ms
[:component:Chatjoy:sharelibrary:compileDebugKotlin]:5241ms
[:component:Chatjoy:sharelibrary:compileDebugJavaWithJavac]:665ms
[:component:Chatjoy:sharelibrary:extractDebugAnnotations]:20770ms
[:component:Chatjoy:sharelibrary:mergeDebugGeneratedProguardFiles]:7ms
[:component:Chatjoy:sharelibrary:mergeDebugConsumerProguardFiles]:4ms
[:component:Chatjoy:picture_library:parseDebugLocalResources]:11ms
[:component:Chatjoy:sharelibrary:compileDebugSources]:1ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugResValues]:2ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugResources]:0ms
[:component:Chatjoy:injectCrashlyticsMappingFileIdChatjoyLocalDevelopDebug]:15ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugGoogleServices]:16ms
[:component:Chatjoy:ucrop:prepareLintJarForPublish]:8492ms
[:component:Chatjoy:dataBindingTriggerChatjoyLocalDevelopDebug]:12ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugBuildConfig]:13ms
[:component:Chatjoy:createChatjoyLocalDevelopDebugCompatibleScreenManifests]:9ms
[:component:Chatjoy:extractDeepLinksChatjoyLocalDevelopDebug]:3ms
[:component:Chatjoy:picture_library:extractDeepLinksDebug]:3ms
[:component:Chatjoy:sharelibrary:extractDeepLinksDebug]:4ms
[:component:Chatjoy:ucrop:extractDeepLinksDebug]:4ms
[:component:Chatjoy:util_library:extractDeepLinksDebug]:4ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugMainManifest]:1121ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugManifest]:18ms
[:component:Chatjoy:picture_library:writeDebugAarMetadata]:20ms
[:component:Chatjoy:dataBindingMergeDependencyArtifactsChatjoyLocalDevelopDebug]:47ms
[:component:Chatjoy:picture_library:prepareLintJarForPublish]:6ms
[:component:Chatjoy:sharelibrary:writeDebugAarMetadata]:14ms
[:component:Chatjoy:dataBindingMergeGenClassesChatjoyLocalDevelopDebug]:138ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugNativeDebugMetadata]:1ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugShaders]:13ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugShaders]:1ms
[:component:Chatjoy:util_library:compileDebugLibraryResources]:45ms
[:component:Chatjoy:checkChatjoyLocalDevelopDebugAarMetadata]:49ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugAssets]:1ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugAssets]:167ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugJavaRes]:1ms
[:component:Chatjoy:picture_library:bundleLibResDebug]:2ms
[:component:Chatjoy:picture_library:javaPreCompileDebug]:12ms
[:component:Chatjoy:sharelibrary:mergeDebugJavaResource]:25ms
[:component:Chatjoy:sharelibrary:syncDebugLibJars]:110ms
[:component:Chatjoy:ucrop:bundleLibResDebug]:1ms
[:component:Chatjoy:checkChatjoyLocalDevelopDebugDuplicateClasses]:389ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugJniLibFolders]:50ms
[:component:Chatjoy:sharelibrary:bundleLibRuntimeToJarDebug]:70ms
[:component:Chatjoy:picture_library:copyDebugJniLibsProjectOnly]:74ms
[:component:Chatjoy:ucrop:generateDebugRFile]:22ms
[:component:Chatjoy:ucrop:compileDebugJavaWithJavac]:1848ms
[:component:Chatjoy:ucrop:extractDebugAnnotations]:2327ms
[:component:Chatjoy:ucrop:mergeDebugGeneratedProguardFiles]:13ms
[:component:Chatjoy:ucrop:mergeDebugConsumerProguardFiles]:6ms
[:component:Chatjoy:ucrop:syncDebugLibJars]:47ms
[:component:Chatjoy:ucrop:bundleDebugAar]:76ms
[:component:Chatjoy:ucrop:compileDebugSources]:0ms
[:component:Chatjoy:ucrop:assembleDebug]:0ms
[:component:Chatjoy:ucrop:compileDebugLibraryResources]:392ms
[:component:Chatjoy:picture_library:compileDebugLibraryResources]:1438ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugResources]:6562ms
[:component:Chatjoy:dataBindingGenBaseClassesChatjoyLocalDevelopDebug]:1400ms
[:component:Chatjoy:sharelibrary:bundleLibCompileToJarDebug]:10ms
[:component:Chatjoy:ucrop:copyDebugJniLibsProjectOnly]:2ms
[:component:Chatjoy:validateSigningChatjoyLocalDevelopDebug]:23ms
[:component:Chatjoy:writeChatjoyLocalDevelopDebugAppMetadata]:7ms
[:component:Chatjoy:writeChatjoyLocalDevelopDebugSigningConfigVersions]:9ms
[:component:Chatjoy:picture_library:generateDebugRFile]:25ms
[:component:Chatjoy:desugarChatjoyLocalDevelopDebugFileDependencies]:49ms
[:component:Chatjoy:sharelibrary:compileDebugLibraryResources]:20177ms
[:component:Chatjoy:compressChatjoyLocalDevelopDebugAssets]:20235ms
[:component:Chatjoy:util_library:parseDebugLocalResources]:20245ms
[:component:Chatjoy:util_library:copyDebugJniLibsProjectOnly]:106ms
[:component:Chatjoy:ucrop:bundleLibCompileToJarDebug]:115ms
[:component:Chatjoy:picture_library:compileDebugJavaWithJavac]:4748ms
[:component:Chatjoy:picture_library:extractDebugAnnotations]:118ms
[:component:Chatjoy:picture_library:mergeDebugGeneratedProguardFiles]:11ms
[:component:Chatjoy:picture_library:mergeDebugConsumerProguardFiles]:3ms
[:component:Chatjoy:picture_library:syncDebugLibJars]:85ms
[:component:Chatjoy:picture_library:bundleDebugAar]:70ms
[:component:Chatjoy:picture_library:compileDebugSources]:0ms
[:component:Chatjoy:picture_library:assembleDebug]:0ms
[:component:Chatjoy:ucrop:bundleLibRuntimeToJarDebug]:8ms
[:component:Chatjoy:util_library:javaPreCompileDebug]:4ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugManifestForPackage]:23ms
[:component:Chatjoy:sharelibrary:copyDebugJniLibsProjectAndLocalJars]:26ms
[:component:Chatjoy:sharelibrary:bundleDebugAar]:45ms
[:component:Chatjoy:sharelibrary:assembleDebug]:0ms
[:component:Chatjoy:sharelibrary:copyDebugJniLibsProjectOnly]:1ms
[:component:Chatjoy:picture_library:bundleLibRuntimeToJarDebug]:11ms
[:component:Chatjoy:mergeExtDexChatjoyLocalDevelopDebug]:135ms
[:component:Chatjoy:picture_library:bundleLibCompileToJarDebug]:148ms
[:component:Chatjoy:sharelibrary:bundleLibResDebug]:160ms
[:component:Chatjoy:util_library:generateDebugRFile]:196ms
[:component:Chatjoy:util_library:compileDebugKotlin]:2678ms
[:component:Chatjoy:util_library:compileDebugJavaWithJavac]:251ms
[:component:Chatjoy:util_library:extractDebugAnnotations]:22ms
[:component:Chatjoy:util_library:mergeDebugGeneratedProguardFiles]:6ms
[:component:Chatjoy:util_library:mergeDebugConsumerProguardFiles]:4ms
[:component:Chatjoy:util_library:compileDebugSources]:0ms
[:component:Chatjoy:util_library:mergeDebugJavaResource]:4ms
[:component:Chatjoy:util_library:syncDebugLibJars]:130ms
[:component:Chatjoy:util_library:bundleDebugAar]:21ms
[:component:Chatjoy:util_library:assembleDebug]:0ms
[:component:Chatjoy:util_library:bundleLibCompileToJarDebug]:9ms
[:component:Chatjoy:util_library:bundleLibRuntimeToJarDebug]:17ms
[:component:Chatjoy:util_library:bundleLibResDebug]:28ms
[:component:Chatjoy:mergeLibDexChatjoyLocalDevelopDebug]:95ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugResources]:1402ms
[:component:Chatjoy:kaptGenerateStubsChatjoyLocalDevelopDebugKotlin]:34867ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugNativeLibs]:8741ms
[:component:Chatjoy:stripChatjoyLocalDevelopDebugDebugSymbols]:722ms
[:component:Chatjoy:kaptChatjoyLocalDevelopDebugKotlin]:7521ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugKotlin]:53627ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugJavaWithJavac]:14159ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugSources]:0ms
[:component:Chatjoy:dexBuilderChatjoyLocalDevelopDebug]:18209ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugJavaResource]:4750ms
[:component:Chatjoy:mergeProjectDexChatjoyLocalDevelopDebug]:4859ms
[:component:Chatjoy:packageChatjoyLocalDevelopDebug]:1797ms
[:component:Chatjoy:assembleChatjoyLocalDevelopDebug]:0ms
構建結(jié)束----------------------
構建總耗時:241909ms

可以看到具體的耗時任務如上,主要是kapt相關的編譯和編譯kotlin代碼
優(yōu)化后 構建總耗時:22751ms

構建時間:2021-05-14 16:11:02
開始構建----------------------
[:clean]:2ms
[:component:Chatjoy:sharelibrary:clean]:87ms
[:component:Chatjoy:sharelibrary:preBuild]:0ms
[:component:Chatjoy:sharelibrary:preDebugBuild]:0ms
[:component:Chatjoy:sharelibrary:compileDebugAidl]:2ms
[:component:Chatjoy:util_library:clean]:3ms
[:component:Chatjoy:util_library:preBuild]:0ms
[:component:Chatjoy:util_library:preDebugBuild]:0ms
[:component:Chatjoy:util_library:compileDebugAidl]:1ms
[:component:Chatjoy:sharelibrary:mergeDebugJniLibFolders]:8ms
[:component:Chatjoy:sharelibrary:mergeDebugNativeLibs]:1ms
[:component:Chatjoy:sharelibrary:stripDebugDebugSymbols]:1ms
[:component:Chatjoy:util_library:mergeDebugJniLibFolders]:1ms
[:component:Chatjoy:util_library:mergeDebugNativeLibs]:0ms
[:component:Chatjoy:util_library:stripDebugDebugSymbols]:1ms
[:component:Chatjoy:util_library:copyDebugJniLibsProjectAndLocalJars]:3ms
[:component:Chatjoy:sharelibrary:copyDebugJniLibsProjectAndLocalJars]:3ms
[:component:Chatjoy:util_library:compileDebugRenderscript]:1ms
[:component:Chatjoy:sharelibrary:compileDebugRenderscript]:1ms
[:component:Chatjoy:ucrop:clean]:2ms
[:component:Chatjoy:ucrop:preBuild]:0ms
[:component:Chatjoy:ucrop:preDebugBuild]:0ms
[:component:Chatjoy:ucrop:compileDebugAidl]:1ms
[:component:Chatjoy:sharelibrary:generateDebugBuildConfig]:1ms
[:component:Chatjoy:util_library:generateDebugBuildConfig]:2ms
[:component:Chatjoy:util_library:generateDebugResValues]:3ms
[:component:Chatjoy:sharelibrary:generateDebugResValues]:3ms
[:component:Chatjoy:ucrop:mergeDebugJniLibFolders]:4ms
[:component:Chatjoy:util_library:generateDebugResources]:0ms
[:component:Chatjoy:sharelibrary:generateDebugResources]:0ms
[:component:Chatjoy:ucrop:mergeDebugNativeLibs]:0ms
[:component:Chatjoy:ucrop:stripDebugDebugSymbols]:0ms
[:component:Chatjoy:ucrop:copyDebugJniLibsProjectAndLocalJars]:3ms
[:component:Chatjoy:ucrop:compileDebugRenderscript]:1ms
[:component:Chatjoy:sharelibrary:packageDebugResources]:9ms
[:component:Chatjoy:ucrop:generateDebugBuildConfig]:1ms
[:component:Chatjoy:ucrop:generateDebugResValues]:3ms
[:component:Chatjoy:ucrop:generateDebugResources]:0ms
[:component:Chatjoy:util_library:packageDebugResources]:0ms
[:component:Chatjoy:sharelibrary:parseDebugLocalResources]:8ms
[:component:Chatjoy:util_library:parseDebugLocalResources]:3ms
[:component:Chatjoy:sharelibrary:processDebugManifest]:11ms
[:component:Chatjoy:util_library:processDebugManifest]:1ms
[:component:Chatjoy:ucrop:packageDebugResources]:26ms
[:component:Chatjoy:ucrop:parseDebugLocalResources]:12ms
[:component:Chatjoy:picture_library:clean]:2ms
[:component:Chatjoy:picture_library:preBuild]:0ms
[:component:Chatjoy:picture_library:preDebugBuild]:0ms
[:component:Chatjoy:picture_library:compileDebugAidl]:1ms
[:component:Chatjoy:ucrop:processDebugManifest]:5ms
[:component:Chatjoy:picture_library:mergeDebugJniLibFolders]:6ms
[:component:Chatjoy:picture_library:mergeDebugNativeLibs]:1ms
[:component:Chatjoy:picture_library:stripDebugDebugSymbols]:0ms
[:component:Chatjoy:picture_library:copyDebugJniLibsProjectAndLocalJars]:4ms
[:component:Chatjoy:picture_library:generateDebugBuildConfig]:12ms
[:component:Chatjoy:ucrop:generateDebugRFile]:4ms
[:component:Chatjoy:picture_library:generateDebugResValues]:4ms
[:component:Chatjoy:ucrop:javaPreCompileDebug]:4ms
[:component:Chatjoy:sharelibrary:generateDebugRFile]:8ms
[:component:Chatjoy:picture_library:processDebugManifest]:4ms
[:component:Chatjoy:util_library:generateDebugRFile]:4ms
[:component:Chatjoy:picture_library:javaPreCompileDebug]:3ms
[:component:Chatjoy:picture_library:mergeDebugShaders]:5ms
[:component:Chatjoy:picture_library:compileDebugShaders]:2ms
[:component:Chatjoy:picture_library:generateDebugAssets]:0ms
[:component:Chatjoy:picture_library:packageDebugAssets]:4ms
[:component:Chatjoy:picture_library:packageDebugRenderscript]:0ms
[:component:Chatjoy:picture_library:prepareLintJarForPublish]:1ms
[:component:Chatjoy:picture_library:processDebugJavaRes]:0ms
[:component:Chatjoy:picture_library:mergeDebugJavaResource]:5ms
[:component:Chatjoy:picture_library:writeDebugAarMetadata]:2ms
[:component:Chatjoy:picture_library:extractDeepLinksDebug]:3ms
[:component:Chatjoy:picture_library:bundleLibResDebug]:1ms
[:component:Chatjoy:picture_library:copyDebugJniLibsProjectOnly]:3ms
[:component:Chatjoy:sharelibrary:compileDebugKotlin]:4ms
[:component:Chatjoy:sharelibrary:javaPreCompileDebug]:3ms
[:component:Chatjoy:util_library:compileDebugKotlin]:5ms
[:component:Chatjoy:util_library:javaPreCompileDebug]:4ms
[:component:Chatjoy:sharelibrary:compileDebugJavaWithJavac]:5ms
[:component:Chatjoy:util_library:compileDebugJavaWithJavac]:9ms
[:component:Chatjoy:util_library:extractDebugAnnotations]:17ms
[:component:Chatjoy:sharelibrary:extractDebugAnnotations]:17ms
[:component:Chatjoy:sharelibrary:mergeDebugGeneratedProguardFiles]:2ms
[:component:Chatjoy:util_library:mergeDebugGeneratedProguardFiles]:3ms
[:component:Chatjoy:sharelibrary:mergeDebugConsumerProguardFiles]:2ms
[:component:Chatjoy:util_library:mergeDebugConsumerProguardFiles]:0ms
[:component:Chatjoy:sharelibrary:mergeDebugShaders]:3ms
[:component:Chatjoy:util_library:mergeDebugShaders]:3ms
[:component:Chatjoy:sharelibrary:compileDebugShaders]:0ms
[:component:Chatjoy:sharelibrary:generateDebugAssets]:0ms
[:component:Chatjoy:util_library:compileDebugShaders]:0ms
[:component:Chatjoy:util_library:generateDebugAssets]:0ms
[:component:Chatjoy:sharelibrary:packageDebugAssets]:2ms
[:component:Chatjoy:sharelibrary:packageDebugRenderscript]:0ms
[:component:Chatjoy:sharelibrary:prepareLintJarForPublish]:1ms
[:component:Chatjoy:util_library:packageDebugAssets]:0ms
[:component:Chatjoy:sharelibrary:processDebugJavaRes]:1ms
[:component:Chatjoy:util_library:packageDebugRenderscript]:0ms
[:component:Chatjoy:util_library:prepareLintJarForPublish]:0ms
[:component:Chatjoy:util_library:processDebugJavaRes]:0ms
[:component:Chatjoy:util_library:mergeDebugJavaResource]:10ms
[:component:Chatjoy:sharelibrary:mergeDebugJavaResource]:13ms
[:component:Chatjoy:util_library:syncDebugLibJars]:13ms
[:component:Chatjoy:ucrop:compileDebugJavaWithJavac]:14ms
[:component:Chatjoy:util_library:writeDebugAarMetadata]:2ms
[:component:Chatjoy:ucrop:extractDebugAnnotations]:18ms
[:component:Chatjoy:sharelibrary:syncDebugLibJars]:3ms
[:component:Chatjoy:ucrop:mergeDebugGeneratedProguardFiles]:3ms
[:component:Chatjoy:ucrop:mergeDebugConsumerProguardFiles]:0ms
[:component:Chatjoy:sharelibrary:writeDebugAarMetadata]:1ms
[:component:Chatjoy:ucrop:mergeDebugShaders]:2ms
[:component:Chatjoy:ucrop:compileDebugShaders]:1ms
[:component:Chatjoy:ucrop:generateDebugAssets]:0ms
[:component:Chatjoy:ucrop:packageDebugAssets]:4ms
[:component:Chatjoy:ucrop:packageDebugRenderscript]:0ms
[:component:Chatjoy:ucrop:prepareLintJarForPublish]:2ms
[:component:Chatjoy:picture_library:compileDebugRenderscript]:0ms
[:component:Chatjoy:ucrop:processDebugJavaRes]:1ms
[:component:Chatjoy:picture_library:generateDebugResources]:0ms
[:component:Chatjoy:ucrop:mergeDebugJavaResource]:2ms
[:component:Chatjoy:ucrop:syncDebugLibJars]:13ms
[:component:Chatjoy:ucrop:writeDebugAarMetadata]:3ms
[:component:Chatjoy:picture_library:packageDebugResources]:81ms
[:component:Chatjoy:picture_library:parseDebugLocalResources]:8ms
[:component:Chatjoy:sharelibrary:bundleDebugAar]:18ms
[:component:Chatjoy:sharelibrary:compileDebugSources]:0ms
[:component:Chatjoy:sharelibrary:assembleDebug]:0ms
[:component:Chatjoy:sharelibrary:extractDeepLinksDebug]:3ms
[:component:Chatjoy:sharelibrary:compileDebugLibraryResources]:9ms
[:component:Chatjoy:sharelibrary:bundleLibCompileToJarDebug]:12ms
[:component:Chatjoy:picture_library:generateDebugRFile]:3ms
[:component:Chatjoy:sharelibrary:bundleLibResDebug]:6ms
[:component:Chatjoy:sharelibrary:bundleLibRuntimeToJarDebug]:12ms
[:component:Chatjoy:util_library:bundleDebugAar]:1ms
[:component:Chatjoy:util_library:compileDebugSources]:0ms
[:component:Chatjoy:util_library:assembleDebug]:0ms
[:component:Chatjoy:sharelibrary:copyDebugJniLibsProjectOnly]:2ms
[:component:Chatjoy:util_library:extractDeepLinksDebug]:3ms
[:component:Chatjoy:util_library:compileDebugLibraryResources]:15ms
[:component:Chatjoy:util_library:bundleLibCompileToJarDebug]:12ms
[:component:Chatjoy:util_library:bundleLibResDebug]:9ms
[:component:Chatjoy:util_library:bundleLibRuntimeToJarDebug]:10ms
[:component:Chatjoy:util_library:copyDebugJniLibsProjectOnly]:3ms
[:component:Chatjoy:picture_library:compileDebugLibraryResources]:14ms
[:component:Chatjoy:ucrop:bundleDebugAar]:87ms
[:component:Chatjoy:ucrop:compileDebugSources]:0ms
[:component:Chatjoy:ucrop:assembleDebug]:0ms
[:component:Chatjoy:ucrop:bundleLibCompileToJarDebug]:11ms
[:component:Chatjoy:ucrop:extractDeepLinksDebug]:3ms
[:component:Chatjoy:ucrop:compileDebugLibraryResources]:34ms
[:component:Chatjoy:ucrop:bundleLibResDebug]:1ms
[:component:Chatjoy:ucrop:bundleLibRuntimeToJarDebug]:13ms
[:component:Chatjoy:ucrop:copyDebugJniLibsProjectOnly]:3ms
[:component:Chatjoy:picture_library:compileDebugJavaWithJavac]:334ms
[:component:Chatjoy:picture_library:extractDebugAnnotations]:16ms
[:component:Chatjoy:picture_library:mergeDebugGeneratedProguardFiles]:5ms
[:component:Chatjoy:picture_library:mergeDebugConsumerProguardFiles]:1ms
[:component:Chatjoy:picture_library:syncDebugLibJars]:20ms
[:component:Chatjoy:picture_library:bundleDebugAar]:491ms
[:component:Chatjoy:picture_library:compileDebugSources]:0ms
[:component:Chatjoy:picture_library:assembleDebug]:0ms
[:component:Chatjoy:picture_library:bundleLibCompileToJarDebug]:23ms
[:component:Chatjoy:picture_library:bundleLibRuntimeToJarDebug]:19ms
[:component:Chatjoy:clean]:3377ms
[:component:Chatjoy:preBuild]:0ms
[:component:Chatjoy:preChatjoyLocalDevelopDebugBuild]:0ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugAidl]:1ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugRenderscript]:1ms
[:component:Chatjoy:dataBindingMergeDependencyArtifactsChatjoyLocalDevelopDebug]:189ms
[:component:Chatjoy:dataBindingMergeGenClassesChatjoyLocalDevelopDebug]:22ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugResValues]:3ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugResources]:0ms
[:component:Chatjoy:injectCrashlyticsMappingFileIdChatjoyLocalDevelopDebug]:10ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugGoogleServices]:8ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugResources]:789ms
[:component:Chatjoy:dataBindingGenBaseClassesChatjoyLocalDevelopDebug]:151ms
[:component:Chatjoy:dataBindingTriggerChatjoyLocalDevelopDebug]:7ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugBuildConfig]:8ms
[:component:Chatjoy:checkChatjoyLocalDevelopDebugAarMetadata]:22ms
[:component:Chatjoy:createChatjoyLocalDevelopDebugCompatibleScreenManifests]:7ms
[:component:Chatjoy:extractDeepLinksChatjoyLocalDevelopDebug]:7ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugMainManifest]:34ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugManifest]:10ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugManifestForPackage]:8ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugResources]:172ms
[:component:Chatjoy:kaptGenerateStubsChatjoyLocalDevelopDebugKotlin]:1408ms
[:component:Chatjoy:kaptChatjoyLocalDevelopDebugKotlin]:470ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugKotlin]:1038ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugJavaWithJavac]:2849ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugSources]:0ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugNativeDebugMetadata]:0ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugShaders]:8ms
[:component:Chatjoy:compileChatjoyLocalDevelopDebugShaders]:0ms
[:component:Chatjoy:generateChatjoyLocalDevelopDebugAssets]:0ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugAssets]:33ms
[:component:Chatjoy:compressChatjoyLocalDevelopDebugAssets]:16ms
[:component:Chatjoy:processChatjoyLocalDevelopDebugJavaRes]:0ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugJavaResource]:790ms
[:component:Chatjoy:checkChatjoyLocalDevelopDebugDuplicateClasses]:42ms
[:component:Chatjoy:dexBuilderChatjoyLocalDevelopDebug]:2929ms
[:component:Chatjoy:mergeLibDexChatjoyLocalDevelopDebug]:20ms
[:component:Chatjoy:mergeProjectDexChatjoyLocalDevelopDebug]:91ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugJniLibFolders]:430ms
[:component:Chatjoy:mergeChatjoyLocalDevelopDebugNativeLibs]:1875ms
[:component:Chatjoy:stripChatjoyLocalDevelopDebugDebugSymbols]:1093ms
[:component:Chatjoy:validateSigningChatjoyLocalDevelopDebug]:6ms
[:component:Chatjoy:writeChatjoyLocalDevelopDebugAppMetadata]:7ms
[:component:Chatjoy:writeChatjoyLocalDevelopDebugSigningConfigVersions]:7ms
[:component:Chatjoy:desugarChatjoyLocalDevelopDebugFileDependencies]:31ms
[:component:Chatjoy:mergeExtDexChatjoyLocalDevelopDebug]:736ms
[:component:Chatjoy:packageChatjoyLocalDevelopDebug]:1744ms
[:component:Chatjoy:assembleChatjoyLocalDevelopDebug]:0ms
構建結(jié)束----------------------
構建總耗時:22751ms

起飛了有木有哈哈懊悯!
優(yōu)化具體步驟
1.在gradle.properties添加如下配置

//開啟gradle并行編譯蜓谋,開啟daemon,調(diào)整jvm內(nèi)存大小
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.parallel=true
org.gradle.jvmargs=-Xmx4096m -XX:MaxPermSize=1024m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8

//開啟gradle緩存
org.gradle.caching=true
android.enableBuildCache=true

//開啟kotlin的增量和并行編譯
kotlin.incremental=true
kotlin.incremental.java=true
kotlin.incremental.js=true
kotlin.caching.enabled=true
kotlin.parallel.tasks.in.project=true //開啟kotlin并行編譯


//優(yōu)化kapt
kapt.use.worker.api=true //并行運行kapt1.2.60版本以上支持
kapt.incremental.apt=true //增量編譯 kapt1.3.30版本以上支持
//kapt avoiding 如果用kapt依賴的內(nèi)容沒有變化炭分,會完全重用編譯內(nèi)容桃焕,省掉最上圖中的:app:kaptGenerateStubsDebugKotlin的時間
kapt.include.compile.classpath=false

2.在app gradle添加如下配置

//kapt添加如下配置
kapt {
    useBuildCache = true
    javacOptions {
        option("-Xmaxerrs", 500)
    }
}

//在Android代碼塊中添加如下配置:(可優(yōu)化transformClassDexBuilderForDebug的時間)
    dexOptions {
        preDexLibraries true
        maxProcessCount 8
    }

以上就是優(yōu)化gradle編譯時間的配置.其他不太重要的優(yōu)化,好像對時間影響不算特別大捧毛。大家也可以根據(jù)自己的項目做針對優(yōu)化观堂。
查看自己項目中gradle編譯中具體所用的時間
1.創(chuàng)建buildTrace.gradle文件

import java.text.SimpleDateFormat

/**
 * 監(jiān)控構建耗時
 *
 * 記錄構建過程中的每個任務的耗時,并寫入文件中 .build_history/buildTimeLog_yy_MM_dd_HH_mm_ss.log中
 *
 * 使用時將文件放在app目錄下,然后在app/build.gradle中添加引用:
 * apply from: "./buildTrace.gradle"
 */

class BuildTimeListener implements TaskExecutionListener, BuildListener {
    private final String BUILD_LOG_FILE_DIR = ".build_history"
    private final String BUILD_LOG_FILE_PATH = "buildTimeLog"
    private long taskStartTime;
    private long buildStartTime;
    private int taskCounts = 0;
    private StringBuilder sb = new StringBuilder()
    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
    private SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss")

    BuildTimeListener() {
        buildStartTime = System.currentTimeMillis()
        //添加一些版本信息
//        sb.append("codeTag:").append(ProjectConfig.codeTag).append("\n")
//        sb.append("branch:").append(ProjectConfig.branch).append("\n")
//        sb.append("versionName:").append(ProjectConfig.versionName).append("\n")
//        sb.append("versionCode:").append(ProjectConfig.versionCode).append("\n")
        sb.append("構建時間:" + sdf.format(new Date()) + "\n")
        sb.append("開始構建----------------------\n")
    }

    @Override
    void buildStarted(Gradle gradle) {

    }

    @Override
    void settingsEvaluated(Settings settings) {

    }

    @Override
    void projectsLoaded(Gradle gradle) {

    }

    @Override
    void projectsEvaluated(Gradle gradle) {

    }

    /**
     * 構建完成回調(diào)
     * @param result The result of the build. Never null.
     */
    @Override
    void buildFinished(BuildResult result) {
        if(taskCounts<5) return
        long buildCost = System.currentTimeMillis() - buildStartTime
        sb.append("構建結(jié)束----------------------\n")
        sb.append("構建總耗時:" + buildCost + "ms")
        //輸出到文件
        String text = sb.toString()
        writeToFile(BUILD_LOG_FILE_PATH, text)
    }

    /**
     * 任務執(zhí)行開始
     * @param task The task about to be executed. Never null.
     */
    @Override
    void beforeExecute(Task task) {
        taskStartTime = System.currentTimeMillis();
    }

    /**
     * 任務執(zhí)行結(jié)束
     * @param task The task which was executed. Never null.
     * @param state The task state. If the task failed with an exception, the exception is available in this
     */
    @Override
    void afterExecute(Task task, TaskState state) {
        long cost = System.currentTimeMillis() - taskStartTime;
        System.out.println("任務:" + task.name + "," + task.path + ",耗時:" + cost);
        sb.append("[" + task.path + "]:" + cost + "ms\n")
        taskCounts++
    }

    private void writeToFile(String fname, String text) {
        File dir = new File(BUILD_LOG_FILE_DIR)
        if (!dir.exists()) {
            dir.mkdir()
        }
        File file = new File(BUILD_LOG_FILE_DIR + File.separator + fname + "_" + sdf2.format(new Date()) + ".log")
        file.write(text, true)
    }
}

gradle.addListener new BuildTimeListener()

2.在app項目中引用

apply from: 'buildTrace.gradle'

大家如果有更好的方案呀忧,還請多多指教师痕!

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市而账,隨后出現(xiàn)的幾起案子胰坟,更是在濱河造成了極大的恐慌,老刑警劉巖泞辐,帶你破解...
    沈念sama閱讀 221,406評論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件笔横,死亡現(xiàn)場離奇詭異,居然都是意外死亡咐吼,警方通過查閱死者的電腦和手機吹缔,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,395評論 3 398
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來锯茄,“玉大人厢塘,你說我怎么就攤上這事。” “怎么了俗冻?”我有些...
    開封第一講書人閱讀 167,815評論 0 360
  • 文/不壞的土叔 我叫張陵礁叔,是天一觀的道長。 經(jīng)常有香客問我迄薄,道長琅关,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,537評論 1 296
  • 正文 為了忘掉前任讥蔽,我火速辦了婚禮涣易,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘冶伞。我一直安慰自己新症,他們只是感情好,可當我...
    茶點故事閱讀 68,536評論 6 397
  • 文/花漫 我一把揭開白布响禽。 她就那樣靜靜地躺著徒爹,像睡著了一般。 火紅的嫁衣襯著肌膚如雪芋类。 梳的紋絲不亂的頭發(fā)上隆嗅,一...
    開封第一講書人閱讀 52,184評論 1 308
  • 那天,我揣著相機與錄音侯繁,去河邊找鬼胖喳。 笑死,一個胖子當著我的面吹牛贮竟,可吹牛的內(nèi)容都是我干的丽焊。 我是一名探鬼主播,決...
    沈念sama閱讀 40,776評論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼咕别,長吁一口氣:“原來是場噩夢啊……” “哼技健!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起顷级,我...
    開封第一講書人閱讀 39,668評論 0 276
  • 序言:老撾萬榮一對情侶失蹤凫乖,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后弓颈,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 46,212評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡删掀,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,299評論 3 340
  • 正文 我和宋清朗相戀三年翔冀,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片披泪。...
    茶點故事閱讀 40,438評論 1 352
  • 序言:一個原本活蹦亂跳的男人離奇死亡纤子,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情控硼,我是刑警寧澤泽论,帶...
    沈念sama閱讀 36,128評論 5 349
  • 正文 年R本政府宣布,位于F島的核電站卡乾,受9級特大地震影響翼悴,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜幔妨,卻給世界環(huán)境...
    茶點故事閱讀 41,807評論 3 333
  • 文/蒙蒙 一鹦赎、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧误堡,春花似錦古话、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,279評論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至悉抵,卻和暖如春肩狂,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背基跑。 一陣腳步聲響...
    開封第一講書人閱讀 33,395評論 1 272
  • 我被黑心中介騙來泰國打工婚温, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人媳否。 一個月前我還...
    沈念sama閱讀 48,827評論 3 376
  • 正文 我出身青樓栅螟,卻偏偏與公主長得像,于是被迫代替她去往敵國和親篱竭。 傳聞我的和親對象是個殘疾皇子力图,可洞房花燭夜當晚...
    茶點故事閱讀 45,446評論 2 359

推薦閱讀更多精彩內(nèi)容