简体   繁体   中英

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.

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)
    }
}

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) }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM