如何使用Firebase Performance Plugin减少项目的构建时间

Firebase Performance Monitor是使您的Android应用程序更好的有用工具。 但是,当您连接它时,我们项目的构建时间立即增加了20-30秒,这是远远不够的。

我们并不孤单,我决定发布在Medium上找到的解决方案。 我希望它可以帮助您节省宝贵的项目组装时间。

如何使用Firebase Performance Plugin减少项目的构建时间


我最近向我的一个项目中添加了Firebase Performance Plugin,并且该应用程序的构建时间急剧增加。 最初,在5到6分钟内添加插件后,组装过程不到20秒。 这种行为很烦人,所以我研究了增加组装时间的原因。

如果仔细观察,您会发现以下Gradle任务花费很长时间:

app:transformClassesWithFirebasePerformancePluginForDebug 

有一个后期编译阶段,该阶段使用Android上的Firebase Performance并导致构建时间增加。

如何解决问题


我应用的修复程序通过在build命令中添加一个参数来解决问题,从而可以在开发期间禁用该插件。

root/buildscript/dependencies块中,在以下情况下包装classpath插件:

 if (!project.hasProperty("disable-performance-plugin")) { classpath('com.google.firebase:firebase-plugins:1.1.5') { exclude group: 'com.google.guava', module: 'guava-jdk5' } } 

是否需要排除com.google.guava取决于该库是否导致与您对Guava的依赖项产生冲突,如文档所述

然后,在app/build.gradle添加以下条件:

 if (!project.hasProperty("disable-performance-plugin")) { apply plugin: 'com.google.firebase.firebase-perf' } 

现在,您可以使用禁用插件的选项,通过命令行简单地构建项目:

 ./gradlew your-task -Pdisable-performance-plugin 

如果您使用Android Studio构建项目,则可以在“编译器设置”部分中添加相同的设置。 您需要设置命令行选项,

 -Pdisable-performance-plugin 

图片

仅此而已。 添加此选项将使您的生活更轻松!

Source: https://habr.com/ru/post/zh-CN414967/


All Articles