Hello, I'm trying to disable firebase performance ...
# gradle
r
Hello, I'm trying to disable firebase performance monitoring instrumentation for debug builds of an Android application. Sadly the examples are only in Groovy and I'm having issues understanding how should I get access to the
FirebasePerformance
object in order to configure it. Documentation https://firebase.google.com/docs/perf-mon/disable-sdk?platform=android Groovy example from the documentation
Copy code
groovy
android {
  // ...
  buildTypes {
    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
      }
    }
  }
}
My
build.gradle.kts
has something like
Copy code
kotlin
  buildTypes {
    getByName("debug") {
        // should disable it here but don't know how to get the reference
    }
Any idea how can I get access to the
FirebasePerformance
object from inside
getByName("debug")
?
1
m
"FirebasePerformance" is an extension on the project, you should be able to get it with something like:
configure<FirebasePerfExtension> {}
I don't think it needs to be in the android closure.
Or something like
Copy code
extensions.getByName("FirebasePerformance") {
    this as FirebasePerfExtension
}
r
Hi Martin. I tried
Copy code
val firebase = extensions.getByName("FirebasePerformance") as FirebasePerfExtension
firebase.setInstrumentationEnabled(true)
But is doesn't exist inside
android{}
or outside
Copy code
Extension with name 'FirebasePerformance' does not exist.
m
damn, right, it's not applied on the project...
Copy code
private static void registerExtension(AppExtension androidExt) {
        androidExt.getBuildTypes().all((buildType) -> {
            ((ExtensionAware)buildType).getExtensions().add("FirebasePerformance", FirebasePerfExtension.class);
        });
        androidExt.getProductFlavors().all((productFlavor) -> {
            ((ExtensionAware)productFlavor).getExtensions().add("FirebasePerformance", FirebasePerfExtension.class);
        });
    }
so something like:
(buildType as ExtensionAware).extensions.getByName("FirebasePerformance")
👀 1
(I just edited to add
extensions
, I think you'll need that)
That should also work on a
productFlavor
, not only
buildType
r
Copy code
buildTypes {
    getByName("debug") {
      val firebasePerf = (this as ExtensionAware).extensions.getByName("FirebasePerformance")
      (firebasePerf as FirebasePerfExtension).setInstrumentationEnabled(true)

...
Nope. Still not found. I was walking this way this morning but could nailed the details...
Copy code
Extension with name 'FirebasePerformance' does not exist. Currently registered extension names: [ext]
Where would you call that function that you sent me?
registerExtension
? maybe that's what's missing 🤔
m
I got it from the plugin jar, it's the code that registers the extension
If you search
FirebasePerfPlugin
in IntelliJ, you should have it
Or maybe the extensions are not registered yet ?
You can also try to hook a debugger with
-Dorg.gradle.debug=true
from the command line and a remote config in idea to see what's going on
r
Ahhh you pointed me to the right place. The plugin was applied in the parent build file but not in the android app module. I added it and the following worked as we expected:
Copy code
buildTypes {
    getByName("debug") {

      val firebasePerf = (this as ExtensionAware).extensions.getByName("FirebasePerformance")
      (firebasePerf as FirebasePerfExtension).setInstrumentationEnabled(true)
...
Thanks for the help man!
👍 1
m
No pb. I hope plugins will do less of this extension magic now that kotlin dsl is a thing. That'll make them more discoverable
🙏 2
r
I would love to see that too!
g
We just avoid application of plugin. Apply when special Gradle property is passed
👍 2
320 Views