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'
大家如果有更好的方案呀忧,還請多多指教师痕!