Firebase Performance Plugin Causes Slow Build Time

When using Firebase Performance in Android Studio, the app:transformClassesWithFirebasePerformancePluginForDebugGradle Task app:transformClassesWithFirebasePerformancePluginForDebugtakes significantly longer than any other task, and therefore significantly slows down the Gradle build time.

Slow assembly is displayed in the profiler

+21
source share
9 answers

Firebase in our project led to an increase in build time by 40%. To speed up debugging builds, we added the ability to enable / disable it using the build options in the app / build.gradle and root build.gradle files:

Application:

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

root / buildscript / dependencies:

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

when starting from the command line use

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

Android Studio :

Android Studio compiler options

+37

, - .

2 .

1. firebasePerformanceInstrumentationEnabled

, SDK, .

:

  • transformClassesWithFirebasePerformancePluginFor* ~ 5-10 .
  • , . <meta-data> AndroidManifest FirebasePerformance.getInstance().setPerformanceCollectionEnabled(). .

:

, , ( ), .

. , . , CI, , Gradle , .

, :

  1. gradle.properties:

    firebasePerformanceInstrumentationEnabled=false
    
  2. CI :

    ./gradlew assemblyRelease -PfirebasePerformanceInstrumentationEnabled = true

:

  • .

:

  • 5-15 .

2. Gradle, firebase-perf Gradle.

:

  • transformClassesWithFirebasePerformancePluginFor * . ~ 5–10 , .
  • , - , . <meta-data> AndroidManifest FirebasePerformance.getInstance().setPerformanceCollectionEnabled(). .

:

, :

  1. build.gradle build.gradle:

    if (project.hasProperty('useFirebasePerf')) {
      apply plugin: 'com.google.firebase.firebase-perf'
    }
    

    : build.gradle build.gradle:

    classpath "com.google.firebase:firebase-plugins:$firebase_plugins_version"
    

    Gradle, .

    guava-jdk5, firebase-plugins v1.1.1 , .

  2. CI :

    ./gradlew AssemblyRelease -PuseFirebasePerf

:

  • , Firebase Performance Gradle.

:

  • Gradle, , .

* ( ) Gradle, firebase-perf SDK

- Firebase Performance SDK ( SDK ), . .

:

, , build.gradle build.gradle:

  • , :

    if (project.property('firebasePerformanceInstrumentationEnabled') == 'true') {
      implementation "com.google.firebase:firebase-perf:${firebase_perf_version}"
    }
    
  • :

    if (project.hasProperty('useFirebasePerf')) {
      implementation "com.google.firebase:firebase-perf:${firebase_perf_version}"
    }
    

:

  • ~ 5-10 , "ProGuarding".

:

  • APK , , 0,5 . , .
  • 64 , MultiDex. , . , Firebase Performance 5K ( ProGuard ).

, .

+25

. :

if (getGradle().getStartParameter().getTaskRequests().toString().contains("Release")) {
    apply plugin: 'com.google.firebase.firebase-perf'
}
+10

transformClassesWithFirebasePerformancePluginForDebug, :

build.gradle:

if (!project.gradle.startParameter.taskNames.any { taskName ->
     taskName.toLowerCase().contains('assemble') && taskName.toLowerCase().contains('debug') }) {
     classpath("com.google.firebase:firebase-plugins:$firebasePluginVersion") {
         exclude group: 'com.google.guava', module: 'guava-jdk5'
     }
}

build.gradle:

if (!project.gradle.startParameter.taskNames.any { taskName ->
    taskName.toLowerCase().contains('assemble') && taskName.toLowerCase().contains('debug') }) {
    apply plugin: 'com.google.firebase.firebase-perf'
}
+5

. , . , , Gradle, , - :

" ". , .

, , . :

.

, , Firebase, (, ). , , , , .

, , Debug Non-Debug. Kotlin, , Groovy:

plugins {
    ...
    id ("com.google.firebase.firebase-perf")
}

...

android {
    ...

    applicationVariants.all {
        val variant = this
        val isFirebaseEnabled = !variant.javaCompiler.name.contains("Debug", true)

        gradle.taskGraph.whenReady {
            if (this.hasTask(variant.javaCompiler))
            {
                project.FirebasePerformance.isInstrumentationEnabled = isFirebaseEnabled
            }
        }
    }

    ...
}

, transformClassesWithFirebasePerformancePluginFor* - , , .

+3

Firebase Performance perf-plugin (v1.3.0). Firebase Performance Monitoring Gradle ( buildTypes productFlavors).

:

 android {
      // ...

      debug {
        FirebasePerformance {
          // Set this flag to 'false' to disable @AddTrace annotation processing and
          // automatic HTTP/S network request monitoring
          // for a specific build variant at compile time.
          instrumentationEnabled false
        }
      }
    }

:

https://firebase.google.com/support/release-notes/android#update_-_july_10_2019

+3

, Android Studio , , Android Studio . - ?

+1

2 fooobar.com/questions/1689536/...

  • gradle.properties

    useFirebasePerf =

  • if (useFirebasePerf.toBoolean()) { : 'com.google.firebase.firebase-perf'}

  • if (useFirebasePerf.toBoolean()) { 'com.google.firebase: firebase-perf: 16.2.3'}

  • CI ( )

    gradlew Release -PuseFirebasePerf =

0

For newer versions of the Firebase Perf plugin ( 1.3.0and higher) with Kotlin DSL, you need to add the following:

android {
  ...
  buildTypes {
    ...
    all {   
      with((this as ExtensionAware).extensions["FirebasePerformance"] as FirebasePerfExtension) {
        setInstrumentationEnabled(!isDebuggable)
      }     
    }
    ...
  }

}

For the Groovy version, you can read the Firebase documentation .

0
source

Source: https://habr.com/ru/post/1689536/


All Articles