Skip to content

fix: Downgrade androidx.metrics dep to beta01 in Gradle build#149

Merged
awforsythe merged 1 commit into
developfrom
aforsythe/RUM-10762/androidx-agp-build-fix
Jul 10, 2025
Merged

fix: Downgrade androidx.metrics dep to beta01 in Gradle build#149
awforsythe merged 1 commit into
developfrom
aforsythe/RUM-10762/androidx-agp-build-fix

Conversation

@awforsythe
Copy link
Copy Markdown
Contributor

@awforsythe awforsythe commented Jul 9, 2025

refs: RUM-10762

What and why?

As explained in RUM-10762, Android builds are broken on Unity 2022 and older, due to a transitive dependency included by dd-sdk-android-rum: namely, androidx.metrics:metrics-performance. As of version 1.0.0-beta02, that library requires an Android Gradle plugin version of 8.6.0 or newer (while versions of Unity prior to Unity 6 are stuck on AGP 7.x). The prior version, 1.0.0-beta01, is compatible with AGP 7.

This PR adds a IPostGenerateGradleAndroidProject callback to Unity Android builds. That callback, implemented as DatadogGradlePostProcessor, does the following:

  • Determines whether the fix needs to be applied: if running Unity 6 or later, we return here and make no changes to gradle.build.
  • Reads the gradle.build file after it's been modified by EDM4U.
  • Finds the section of the file where EDM4U has declared dependencies, then locates the declaration of dd-sdk-android-rum as a dependency within that section. If we can find no such declaration, we return here and make no changes.
  • Checks the declaration to see if it's already been modified: if so, we return here and make no changes.
  • Replaces the implementation specifier for dd-sdk-android-rum with one that explicitly excludes androidx.metrics:metrics-performance, preserving the existing version specifier for dd-sdk-android-rum
  • Adds an extra implementation specifier that explicitly pulls in androidx.metrics:metrics-performance at the desired (older) version

I've also added tests to cover these cases.

The net result is that after EDM4U generates a build.gradle file containing this dependencies block:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.datadoghq:dd-sdk-android-logs:2+' // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:10
    implementation 'com.datadoghq:dd-sdk-android-ndk:2+' // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:12
    implementation 'com.datadoghq:dd-sdk-android-rum:2+' // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:8
// Android Resolver Dependencies End

    constraints {
         implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
             because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
         }
    }

}

...we will further modify it to:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
// Android Resolver Dependencies Start
    implementation 'com.datadoghq:dd-sdk-android-logs:2+' // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:10
    implementation 'com.datadoghq:dd-sdk-android-ndk:2+' // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:12
    implementation('com.datadoghq:dd-sdk-android-rum:2+') { // Packages/com.datadoghq.unity/Editor/DatadogDependencies.xml:8
        // DatadogGradlePostProcessor: exclude the dependency on androidx.metrics:metrics-performance:1.0.0-beta02
        // Version beta02 requires Android Gradle plugin 8.6.0+, which is not supported on Unity 2022 and older
        exclude group: 'androidx.metrics', module: 'metrics-performance'
    }
    // DatadogGradlePostProcessor: Explicitly require version beta01 of the same dependency, as it works with AGP 7
    implementation 'androidx.metrics:metrics-performance:1.0.0-beta01'
// Android Resolver Dependencies End

    constraints {
         implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.0") {
             because("kotlin-stdlib-jdk8 is now a part of kotlin-stdlib")
         }
    }

}

This unblocks Android Unity builds, at the cost of using an older version of androidx.metrics:metrics-performance.

The net effect of this fix is similar to the fix employed for dd-sdk-reactnative: it's simply a bit more complicated to execute since the build.gradle file is generated by Unity (and post-processed by EDM4U) on a per-project basis.

Review checklist

  • This pull request has appropriate unit and / or integration tests

@awforsythe awforsythe marked this pull request as ready for review July 9, 2025 18:29
@awforsythe awforsythe requested a review from a team as a code owner July 9, 2025 18:29
@awforsythe
Copy link
Copy Markdown
Contributor Author

CI jobs for this PR were routinely failing due to an unrelated flaw in the CI scripts (in short: writing subprocess output to stdout asynchronously can raise BlockingIOError if output buffers become full). So I instead validated this change in a separate branch that contains fixes for those CI issues: https://gitlab.ddbuild.io/DataDog/dd-sdk-unity/-/pipelines/70106481

Bypassing checks.

@awforsythe awforsythe merged commit 92030ce into develop Jul 10, 2025
1 of 7 checks passed
@awforsythe awforsythe deleted the aforsythe/RUM-10762/androidx-agp-build-fix branch July 10, 2025 11:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants