How can I define an ext property from Heap.io with gradle kotlin dsl

407 views Asked by At

Im using the heap.io and their Android SDK and they advise you to setup their library like:

  • build.gradle:
android {
    defaultConfig {
        // Add this section to enable Heap event capture.
        ext {
          heapEnabled = true
        }
        // ...
    }
    // ...
}

But this is using the gradle groovy sintax, Im trying to use it with the Kotlin DSL of gradle like:

  • build.gradle.kts
android {
    defaultConfig {
        ext {
            set("heapEnabled", true)
        }

But it does not work for some reason, so:

Why that may be happening?

3

There are 3 answers

0
Daniel Gomez Rico On BEST ANSWER

I was able to make it work using withGroovyBuilder like:

android {
    defaultConfig {
        withGroovyBuilder {
            "ext" {
                setProperty("heapEnabled", LhConfig.isAnalyticEnabled(project))
            }
        }

I still dont understand where is the issue :(

0
Erik B On

extra.set("heapEnabled", false)

0
salbury On

This works:

(this as ExtensionAware).extensions.extraProperties.set("heapEnabled", true)

I believe Heap is looking into making it so the cast isn't necessary.