2

I have an Android project, using a Gradle build configuration written in the kotlin-dsl and trying to apply Dynatrace:

buildscript {
  repositories {
    jcenter()
  }
  dependencies {
    classpath("com.dynatrace.tools:android:7.2.4.1262")
  }
}

// I apply the plugin
apply(plugin = "com.dynatrace.tools.android")

Everything runs smoothly until I try to use the dynatrace configuration block, which is never resolved:

dynatrace {
    defaultConfig {
       ....
    }
}

This is the environment I am working with:

  • Gradle: 5.1.1
  • Android Gradle plugin: 3.4.1
  • Dynatrace version: 7.2.4.1262

I am following Dynatrace's own instructions, and even though they don't mention how to perform the configuration with the kotlin-dsl, they have just added support for it.

Any help would be appreciated.

Hrafn
  • 2,867
  • 3
  • 25
  • 44

2 Answers2

1

I have tried it with the apply DSL and it didn't work. I got it working applying the plugin via plugins DSL.

Top level build.gradle.kts:

buildscript {
    repositories {
        google()
        jcenter()

    }
    dependencies {
        classpath("com.android.tools.build:gradle:3.5.0-beta01")
        classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.31")
        classpath("com.dynatrace.tools:android:7.2.4.1262")
    }
}

allprojects {
    repositories {
        google()
        jcenter()  
    }
}

App build.gradle.kts:

plugins {
    id("com.android.application")
    kotlin("android")
    id("com.dynatrace.tools.android")
    ...
}

android {
    defaultConfig {
        ...
    }
    buildTypes {
        ...
    }
}

dynatrace {
    defaultConfig {
        ...
    }
}

dependencies {
    ...
}

Diego Malone
  • 1,044
  • 9
  • 25
  • I had tried that but receive an error that the plugin wasn't found. Are you pulling it from jcenter? – Hrafn Jun 03 '19 at 18:10
  • Put it on your app `build.gradle.kts`, not in your top level `build.gradle.kts` – Diego Malone Jun 03 '19 at 18:11
  • I have both the dependency and plugin in my application level gradle file, not the top level one. – Hrafn Jun 03 '19 at 19:05
  • You should have the classpath dependency on your top level `build.gradle.kts` and the `plugins` DSL call in your app `build.gradle.kts`. I have tried many combinations here and I couldn't make it work with the classpath in my app's `build.gradle.kts`. – Diego Malone Jun 03 '19 at 19:20
  • I have also tried that, but still receive an error (that the plugin id was not found) when trying to resolve the plugin. – Hrafn Jun 03 '19 at 19:34
  • I have updated my answer to having my top level and my app `build.gradle.kts`. This configuration enabled my `dynatrace` configuration block. – Diego Malone Jun 03 '19 at 19:47
  • 1
    A cache invalidation and restart later I have everything working, after putting the dependency into the project root. Thank you for the assistance. – Hrafn Jun 03 '19 at 19:48
0

I had the same problem trying to migrate my build.gradle to KTS (with dynatrace configuration on it). I had some problems finding the right documentation in Dynatrace website, but at the end I found it (https://www.dynatrace.com/support/help/how-to-use-dynatrace/real-user-monitoring/setup-and-configuration/mobile-apps/instrument-android-app/instrumentation-via-plugin/instrumentation-via-plugin/#tabgroup-android-gradle-plugin--groovy)

The solution in my case, within the Top level build.gradle.kts:

buildscript {
  repositories {
        google()
        mavenCentral()
  }
  dependencies {
    classpath("com.dynatrace.tools.android:gradle-plugin:8.207.1.1004")
  }
}

apply(plugin = "com.dynatrace.instrumentation")
configure<com.dynatrace.tools.android.dsl.DynatraceExtension> {
    configurations {
        create("prod") {
            variantFilter("[rR]elease")
            autoStart {
                applicationId("xxx")
                beaconUrl("yyy")
            }
            userOptIn(true)
            userActions.timeout(5000)
        }
        create("debug") {
            autoStart {
                applicationId("aaa")
                beaconUrl("bbb")
            }
            userOptIn(true)
            userActions.timeout(5000)
        }
    }
}