Skip to content

fix(cli): Find the Android app module when AGP comes from a version catalog - #2804

Merged
antonis merged 1 commit into
mainfrom
fix/android-wizard-version-catalog
Dec 2, 2026
Merged

antonis merged 1 commit into
mainfrom
fix/android-wizard-version-catalog

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

This comes from testing the Android wizard port on fresh Android Studio (AGP 9) projects, see getsentry/sentry-java#6797.

Android Studio projects created since 2023 apply the Android Gradle plugin through the version catalog:

plugins {
    alias(libs.plugins.android.application)
}

with gradle/libs.versions.toml declaring android-application = { id = "com.android.application", version.ref = "agp" }. selectAppFile only matched the literal com.android.application id, so sentry wizard android found no app module and asked "Unable to find your app's directory" in every new project. No flag answers that question, so runs without a terminal stopped there too.

selectAppFile now also treats a module as an app module when:

  • its plugins {} block applies an alias from the [plugins] table of the root project's gradle/libs.versions.toml whose id is com.android.application. Catalog keys and accessors are compared with -, _ and . normalized to ., as Gradle generates accessors, so android-application (libs.plugins.android.application) and older keys like androidApplication (libs.plugins.androidApplication) both resolve. Kotlin alias(…) and Groovy alias … both work. alias(…) apply false, as in the root build script, doesn't count, and commented-out lines are ignored.
  • it sets an applicationId in defaultConfig, which library modules don't have (testApplicationId and applicationIdSuffix don't match).

The literal match is unchanged, and so is what happens after detection: one app module is used directly, several are picked from a list, and none still asks for the path.

The catalog is read by version-catalog.ts, a small line-based reader of the [plugins] table that handles the inline ({ id = "…" }), "id:version", dotted-key (alias.id = "…") and table ([plugins.alias]) forms. The CLI has no TOML parser, and this is too narrow to justify adding one.

selectAppFile now takes the root project directory, used to find the catalog and to resolve the build file paths.

@sentry/wizard (getsentry/sentry-wizard) has the same detection and needs the same fix separately.

via Antonis Lilis.

--

View Session [Sentry]

…atalog

Android Studio projects created since 2023 apply the Android Gradle plugin
with `alias(libs.plugins.android.application)` and declare its id in
`gradle/libs.versions.toml`. `selectAppFile` matched only the literal
`com.android.application` id, so `sentry wizard android` asked for the
app's build file in every new project, a question no flag answers.

The app module is now also recognized when:

- its `plugins {}` block applies a `[plugins]` alias of the root project's
  catalog whose id is `com.android.application`. Aliases and accessors are
  compared with `-`, `_` and `.` normalized to `.`, as Gradle generates
  them, so `android-application`, `android_application` and
  `androidApplication` all resolve. `apply false`, as in the root build
  script, does not count.
- it sets an `applicationId` in `defaultConfig`, which library modules
  don't have.

The catalog is read with a small line-based reader of the `[plugins]`
table (inline, `id:version`, dotted-key and table forms), not a TOML
dependency. One, several, or no app modules are handled as before.

Co-Authored-By: Antonis Lilis <antonis.lilis@sentry.io>
@vercel

vercel Bot commented Dec 2, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
cli Ready Ready Preview Dec 2, 2026 3:43pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
sentry-local Skipped Skipped Dec 2, 2026 3:43pm UTC

Request Review

@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 2, 2026
@antonis
antonis added this pull request to the merge queue Dec 2, 2026
Merged via the queue into main with commit 4fdac04 Dec 2, 2026
32 checks passed
@antonis
antonis deleted the fix/android-wizard-version-catalog branch December 2, 2026 16:37
antonis added a commit that referenced this pull request Dec 2, 2026
…adle-check

Resolve the Android wizard test conflicts with #2804 and #2808: keep
writeActivity(), which returns the Activity's path, and define main's
writeAppWithActivity() on top of it; keep both fs imports; drop the
Sentry import that both sides added.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active and 1 inactive deployments
Preview – cli — a775e8e7 Deployed Dec 2, 2026 by vercel[bot]
Preview – sentry-local — a775e8e7 Deployed Dec 2, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant