Kotlin 让人既爱有恨之编译速度优化
写kotlin很久了,一直以来都不太满意kotlin的编译速度,特别是项目中大量使用kapt 。但是也能忍受。但自从我的电脑让我玩坏了之后。编译速度一度让我怀疑人生,总感觉星哥顺走了我的内存条。可惜我这里监控盲区😂,废话不多说让我们看看具体步骤
优化前和优化后速度对
优化之前构建总耗时: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
构建结束----------------------
构建总耗时:241909ms
可以看到具体的耗时任务如上,主要是kapt相关的编译和编译kotlin代码
优化后 构建总耗时: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
构建结束----------------------
构建总耗时:22751ms
起飞了有木有哈哈!
优化具体步骤
1.在gradle.properties添加如下配置
//开启gradle并行编译,开启daemon,调整jvm内存大小
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并行编译
//优化kapt
kapt.use.worker.api=true //并行运行kapt1.2.60版本以上支持
kapt.incremental.apt=true //增量编译 kapt1.3.30版本以上支持
//kapt avoiding 如果用kapt依赖的内容没有变化,会完全重用编译内容,省掉最上图中的:app:kaptGenerateStubsDebugKotlin的时间
kapt.include.compile.classpath=false
2.在app gradle添加如下配置
//kapt添加如下配置
kapt {
useBuildCache = true
javacOptions {
option("-Xmaxerrs", 500)
}
}
//在Android代码块中添加如下配置:(可优化transformClassDexBuilderForDebug的时间)
dexOptions {
preDexLibraries true
maxProcessCount 8
}
以上就是优化gradle编译时间的配置.其他不太重要的优化,好像对时间影响不算特别大。大家也可以根据自己的项目做针对优化。
查看自己项目中gradle编译中具体所用的时间
1.创建buildTrace.gradle文件
import java.text.SimpleDateFormat
/**
* 监控构建耗时
*
* 记录构建过程中的每个任务的耗时,并写入文件中 .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) {
}
/**
* 构建完成回调
* @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("构建结束----------------------\n")
sb.append("构建总耗时:" + buildCost + "ms")
//输出到文件
String text = sb.toString()
writeToFile(BUILD_LOG_FILE_PATH, text)
}
/**
* 任务执行开始
* @param task The task about to be executed. Never null.
*/
@Override
void beforeExecute(Task task) {
taskStartTime = System.currentTimeMillis();
}
/**
* 任务执行结束
* @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'
大家如果有更好的方案,还请多多指教!
网友评论