Skip to content

Fix datadog-configuration.gradle on Android Gradle Plugin 9 - #1511

Open
radko93 wants to merge 1 commit into
DataDog:developfrom
radko93:fix/agp9-configuration-sourceset-provider
Open

radko93 wants to merge 1 commit into
DataDog:developfrom
radko93:fix/agp9-configuration-sourceset-provider

Conversation

@radko93

@radko93 radko93 commented Oct 23, 2026

Copy link
Copy Markdown

What does this PR do?

Makes datadog-configuration.gradle work on Android Gradle Plugin (AGP) 9.

Today, any app that applies this script (native initialization) fails to build on AGP 9:

You cannot add Provider instances to the Android SourceSet API.

The script adds the folder holding the copied datadog-configuration.json to the app's assets by passing a lazy Provider to srcDir, and AGP 9 no longer accepts that.

With this change, on AGP 7.3 and later:

  • each build variant gets a small task that copies the config file
  • that task's output folder is added to the variant's assets with variant.sources.assets.addGeneratedSourceDirectory, which is the API AGP's error message points to

Older AGP versions keep the current code, unchanged.

Motivation

React Native 0.88 / Expo SDK 58 projects are on AGP 9, so our staging and release builds with native initialization stopped building. The only workaround is android.sourceset.disallowProvider=false, which AGP describes as a temporary escape hatch.

Side benefit: the file used to be copied while Gradle was configuring the project, not when a task ran. With the Gradle configuration cache on, an edited config file did not make it into the APK, and after cleaning the build folder the file was missing. The file is now a task input, so edits are picked up.

Additional Notes

Tested with a minimal app module, checking that assets/datadog-configuration.json is in the APK:

  • AGP 9.2.1 / Gradle 9.4.1: build failed before, works now
  • AGP 8.7.2 / Gradle 8.13: works before and after
  • AGP 7.4.2 / Gradle 7.5.1: works (new code path)
  • AGP 7.2.2 / Gradle 7.5.1: works (old code path)

Also tested in an Expo SDK 58 app (AGP 9.2.1) without the escape hatch: the build passes, the file is in the APK, and the SDK initializes from it on an Android 15 emulator.

One visible change: on AGP 7.3+ the copy task is now per variant (copyDatadogConfigurationFileDebug, copyDatadogConfigurationFileRelease, ...) instead of a single copyDatadogConfigurationFile.

🤖 Generated with Claude Code

AGP 9 rejects Provider instances in the SourceSet API, so applying the
script failed at configuration time. On AGP 7.3+ the configuration file
is now copied by a per-variant task and registered with
variant.sources.assets.addGeneratedSourceDirectory. Older AGP versions
keep the existing code path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 23, 2026 16:24
@radko93
radko93 requested a review from a team as a code owner October 23, 2026 16:24
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-23T16:29:58.261189Z 40f66a5 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No blocking issues were identified in the task implementation, variant asset registration, or legacy fallback.

No open issues 🎉

What changed in this PR

Updates the Android configuration script to support AGP 9 by registering the copied Datadog configuration as generated variant assets.

Changes:

  • Adds per-variant copy tasks with declared inputs and outputs on AGP 7.3+, enabling Gradle to track configuration file changes.
  • Uses the generated-assets API instead of passing a Provider to the SourceSet API.
  • Preserves the existing behavior for older AGP versions.
File Description
packages/​core/​datadog-configuration.gradle Adds version-gated copy tasks and generated asset registration while retaining the legacy fallback.

Review effort: Balanced

@datadog-datadog-prod-us1-2 datadog-datadog-prod-us1-2 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bits Code Review: PASS

More details

The generated-assets task wiring and legacy AGP fallback appear correct based on the completed static review. Android builds were not executed, so compatibility across the claimed AGP versions remains unverified.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Bits Code Review · Commit 40f66a5

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 40f66a574b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

) {
it.configurationFile.set(configurationFile)
}
variant.sources.assets?.addGeneratedSourceDirectory(copyTask, { it.outputDirectory })

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Assign an output directory before wiring the task

On every AGP 7.3+ build that applies this script, addGeneratedSourceDirectory wires the task's existing DirectoryProperty but does not choose a filesystem location for it. Because the registration block sets only configurationFile, AGP or the task action eventually queries an unset outputDirectory and the variant fails before the asset can be copied; set that property to a per-variant build directory when registering the task.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. addGeneratedSourceDirectory sets the location itself: AGP assigns the wired DirectoryProperty to build/generated/assets/<taskName>/, so no explicit value is needed. In the test builds the file lands at app/build/generated/assets/copyDatadogConfigurationFileDebug/datadog-configuration.json on AGP 7.4.2, 8.7.2 and 9.2.1, and ends up in the APK.

This branch has not been deployed

No deployments
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