Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to configure Firebase Performance Monitoring plugin extension in Gradle Kotlin DSL

I have an Android app using Gradle with Kotlin DSL. I'm adding Firebase Performance Monitoring, but I would like for it to be enabled only for a specific build type.

I've been following the instructions provided at Firebase - Disable Firebase Performance Monitoring. Unfortunately the provided snippets are in Groovy.

I've tried to get a reference to the Firebase Performance Monitoring extension in my app level Gradle script by doing the following:

    plugins {
        ...
        id("com.google.firebase.firebase-perf")
        kotlin("android")
        kotlin("android.extensions")
        kotlin("kapt")
    }

    buildTypes {
        getByName(BuildTypes.DEBUG) {
            configure<com.google.firebase.perf.plugin.FirebasePerfExtension> {
                setInstrumentationEnabled(false)
            }
        }
        ...
    }

    ...

    dependencies {
        val firebaseVersion = "17.2.1"
        implementation("com.google.firebase:firebase-core:$firebaseVersion")
        implementation("com.google.firebase:firebase-analytics:$firebaseVersion")
        implementation("com.google.firebase:firebase-perf:19.0.5")
    }

Android Studio doesn't see any problem in this and auto-completes FirebasePerfExtension. Unfortunately upon running a Gradle sync I get the following:

Extension of type 'FirebasePerfExtension' does not exist. 
Currently registered extension types: [ExtraPropertiesExtension, DefaultArtifactPublicationSet, ReportingExtension, SourceSetContainer, JavaPluginExtension, NamedDomainObjectContainer<BaseVariantOutput>, BaseAppModuleExtension, CrashlyticsExtension, KotlinAndroidProjectExtension, KotlinTestsRegistry, AndroidExtensionsExtension, KaptExtension]

There's no plugin extension related to Firebase Performance Monitoring.

This is in my project level build.gradle file dependencies block:

classpath("com.google.firebase:perf-plugin:1.3.1")

Any help is appreciated!

Update 1

As recommended on the Gradle - Migrating build logic from Groovy to Kotlin guide at "Knowing what plugin-provided extensions are available" I've ran the kotlinDslAccessorsReport task. None of the resulting extensions seems to be related to Firebase.

like image 810
Kamal Kamal Mohamed Avatar asked Mar 23 '20 04:03

Kamal Kamal Mohamed


2 Answers

We used this answer, util we discovered a better working way in the team

check(this is ExtensionAware)
configure<com.google.firebase.perf.plugin.FirebasePerfExtension> { setInstrumentationEnabled(false) }
like image 80
Islam Salah Avatar answered Nov 08 '22 16:11

Islam Salah


Had the same issue and was going to apply from groovy file, but seems i found the solution in here: https://docs.gradle.org/5.0/userguide/kotlin_dsl.html#sec:interoperability

withGroovyBuilder {
   "FirebasePerformance" {
       invokeMethod("setInstrumentationEnabled", false)
    }
}
like image 35
santoni7 Avatar answered Nov 08 '22 15:11

santoni7