Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
949060d
feat(cli): add sentry wizard with Next.js
sentry-junior[bot] Nov 26, 2026
76e162b
feat(cli): add the wizard's shared AST and URL helpers
sentry-junior[bot] Nov 26, 2026
0113841
feat(cli): reject the wizard's removed sign-up flags
sentry-junior[bot] Nov 26, 2026
7e5f894
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
0574155
feat(cli): add Android and Flutter to sentry wizard
sentry-junior[bot] Nov 26, 2026
fdeb80f
test(cli): pick an unported integration for the wizard's not-availabl…
sentry-junior[bot] Nov 26, 2026
39e20d5
fix(cli): address review findings in sentry wizard
sentry-junior[bot] Nov 26, 2026
c4786b3
Merge branch 'feat/cli-wizard-scaffold' into feat/cli-wizard-shared-a…
sentry-junior[bot] Nov 26, 2026
3921356
fix(cli): stop the Android wizard on expected project states
sentry-junior[bot] Nov 26, 2026
2c98751
refactor(cli): reuse existing CLI helpers in the wizard AST utils
sentry-junior[bot] Nov 26, 2026
ac6b75d
feat(cli): use positionals and existing CLI flags in sentry wizard
sentry-junior[bot] Nov 26, 2026
4c93aa8
fix(cli): use the credential host for the project issues URL
sentry-junior[bot] Nov 26, 2026
2f2f91a
fix(mcp): regenerate the chart app after the for…of conversion
sentry-junior[bot] Nov 26, 2026
f0a48de
Merge remote-tracking branch 'origin/feat/cli-wizard-scaffold' into f…
sentry-junior[bot] Nov 26, 2026
35bb707
fix(cli): update the Android and Flutter wizards for the new wizard base
sentry-junior[bot] Nov 26, 2026
76bf36c
Merge origin/main into feat/cli-wizard-android-flutter
sentry-junior[bot] Nov 27, 2026
5cd3f7a
fix(cli): write defaults.url to sentry.properties for self-hosted And…
sentry-junior[bot] Nov 27, 2026
aa3ac7e
fix(cli): harden the Flutter and Android wizard edits
sentry-junior[bot] Nov 27, 2026
048dea4
fix(cli): find a main activity named without a package in the Android…
sentry-junior[bot] Nov 27, 2026
c158f2f
fix(cli): handle more Android and Flutter file shapes in the wizard
sentry-junior[bot] Nov 27, 2026
f293b67
fix(cli): tighten main activity and arrow main matching in the wizard
sentry-junior[bot] Nov 27, 2026
3a6626c
fix(cli): ignore commented pubspec entries and imports in the Flutter…
sentry-junior[bot] Nov 27, 2026
3f6cafd
refactor(cli): move the wizard XML reader to shared wizard utils
sentry-junior[bot] Nov 27, 2026
3850e9b
Merge remote-tracking branch 'origin/main' into feat/cli-wizard-andro…
sentry-junior[bot] Nov 27, 2026
97e1c17
refactor(cli): use the shared XML entity decoder in Apple Snapshots
sentry-junior[bot] Nov 27, 2026
0f7b03a
fix(cli): only skip main.dart when it already calls SentryFlutter.init
sentry-junior[bot] Nov 27, 2026
1ddc14e
fix(cli): only promise a Flutter test error when main.dart was patched
sentry-junior[bot] Nov 27, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
234 changes: 234 additions & 0 deletions packages/cli/src/lib/wizard/android/android-wizard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/**
* The Android wizard: adds the Sentry Android Gradle plugin, configures the
* SDK in `AndroidManifest.xml`, patches the main activity with a test error,
* and writes `sentry.properties` for the plugin's ProGuard mapping upload.
* Ported from sentry-wizard's `src/android`.
*/

import { readdirSync } from "node:fs";
import path from "node:path";
import chalk from "chalk";
import { Sentry, traceStep, withTelemetry } from "../telemetry.js";
import { abortIfSpotlightNotSupported } from "../utils/abort-if-sportlight-not-supported.js";
import {
type CliSetupConfig,
abort,
abortIfCancelled,
addSentryCliConfig,
confirmContinueIfNoOrDirtyGitRepo,
getOrAskForProjectData,
printWelcome,
propertiesCliSetupConfig,
} from "../utils/clack/index.js";
import { offerProjectScopedMcpConfig } from "../utils/clack/mcp-config.js";
import { clack } from "../utils/clack/prompts.js";
import { fixLineEndings } from "../utils/line-endings.js";
import type { WizardOptions } from "../utils/types.js";
import { findActivitySourceFile, patchMainActivity } from "./code-tools.js";
import { addGradlePlugin, getNamespace, selectAppFile } from "./gradle.js";
import { addManifestSnippet, getMainActivity } from "./manifest.js";

const proguardMappingCliSetupConfig: CliSetupConfig = {
...propertiesCliSetupConfig,
name: "proguard mappings",
};

/** Run the Android wizard in its telemetry span. */
export async function runAndroidWizard(options: WizardOptions): Promise<void> {
return await withTelemetry(
{
enabled: options.telemetryEnabled,
integration: "android",
wizardOptions: options,
},
() => runAndroidWizardWithTelemetry(options),
);
}

async function runAndroidWizardWithTelemetry(
options: WizardOptions,
): Promise<void> {
printWelcome({
wizardName: "Sentry Android Wizard",
});

await confirmContinueIfNoOrDirtyGitRepo({
ignoreGitChanges: options.ignoreGitChanges,
cwd: undefined,
});

const projectDir = process.cwd();
const buildGradleFiles = findFilesWithExtensions(projectDir, [
".gradle",
"gradle.kts",
]);

if (buildGradleFiles.length === 0) {
clack.log.error(
"No Gradle project found. Please run this command from the root of your project.",
);
return await abort();
}

const appFile = await traceStep("Select App File", () =>
selectAppFile(buildGradleFiles),
);

const projectData = await getOrAskForProjectData(options, "android");

if (projectData.spotlight) {
return await abortIfSpotlightNotSupported("Android");
}

const { selectedProject, selfHosted, sentryUrl, authToken } = projectData;

// Ask if user wants to enable Sentry Logs
const enableLogs = await abortIfCancelled(
clack.confirm({
message:
"Do you want to enable Logs? (See https://docs.sentry.io/platforms/android/logs/)",
}),
);
Sentry.setTag("enable-logs", enableLogs);

if (enableLogs) {
clack.log.info(
"Logs will be enabled with default settings. You can send logs using the Sentry.logger() APIs or use one of the integrations: https://docs.sentry.io/platforms/android/logs/#integrations.",
);
}

// ======== STEP 1. Add Sentry Gradle Plugin to build.gradle(.kts) ============
clack.log.step(
`Adding ${chalk.bold("Sentry Gradle plugin")} to your app's ${chalk.cyan(
"build.gradle",
)} file.`,
);
const pluginAdded = await traceStep("Add Gradle Plugin", () =>
addGradlePlugin(
appFile,
selectedProject.organization.slug,
selectedProject.slug,
),
);
Sentry.setTag("gradle-plugin-added", pluginAdded);
if (!pluginAdded) {
clack.log.error(
`The Gradle sync failed after adding the ${chalk.bold("Sentry Gradle plugin")} to ${chalk.cyan(appFile)}. Fix the build, or set up the plugin by hand.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#install`,
);
return await abort();
}

// ======== STEP 2. Configure Sentry SDK via AndroidManifest ============
clack.log.step(
`Configuring Sentry SDK via ${chalk.cyan("AndroidManifest.xml")}`,
);
const appDir = path.dirname(appFile);
const manifestFile = path.join(appDir, "src", "main", "AndroidManifest.xml");

const manifestUpdated = traceStep("Update Android Manifest", () =>
addManifestSnippet(
manifestFile,
selectedProject.keys[0].dsn.public,
enableLogs,
),
);
if (!manifestUpdated) {
clack.log.warn(
"Could not configure the Sentry SDK. You'll have to do it manually.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#configure",
);
}
Sentry.setTag("android-manifest-updated", manifestUpdated);

// ======== STEP 3. Patch Main Activity with a test error snippet ============
clack.log.step(
`Patching ${chalk.bold("Main Activity")} with a test error snippet.`,
);
const mainActivity = traceStep("Find Main Activity", () =>
getMainActivity(manifestFile),
);
let packageName = mainActivity.packageName;
if (!packageName) {
// if no package name in AndroidManifest, look into gradle script
packageName = getNamespace(appFile);
}
const activityName = mainActivity.activityName;
Sentry.setTag("has-activity-name", !!activityName);
Sentry.setTag("has-package-name", !!packageName);
if (!activityName || !packageName) {
clack.log.error(
"Could not find the Activity with intent action MAIN, or the app's package name. You'll have to finish the setup by hand.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify",
);
return await abort();
}
const packageNameStable = packageName;
const activityFile = await traceStep("Find Main Activity Source File", () =>
findActivitySourceFile(appDir, packageNameStable, activityName),
);

const activityPatched = traceStep("Patch Main Activity", () =>
patchMainActivity(activityFile),
);
if (!activityPatched) {
clack.log.warn(
"Could not patch main activity. You'll have to manually verify the setup.\nPlease follow the instructions at https://docs.sentry.io/platforms/android/#verify",
);
Comment thread
sentry-junior[bot] marked this conversation as resolved.
Resolved
}
Sentry.setTag("main-activity-patched", activityPatched);

// ======== STEP 4. Add sentry.properties for the Gradle plugin ============
clack.log.step(
`Adding the auth token for the ${chalk.bold(
"Sentry Android Gradle plugin",
)} to ${chalk.cyan("sentry.properties")}.`,
);

await addSentryCliConfig(
{ authToken, url: selfHosted ? sentryUrl : undefined },
proguardMappingCliSetupConfig,
);

// Offer optional project-scoped MCP config for Sentry with org and project scope
await offerProjectScopedMcpConfig(
selectedProject.organization.slug,
selectedProject.slug,
);

// Fix mixed line endings caused by inserting LF content into CRLF files (Windows)
fixLineEndings();

// ======== OUTRO ========
const issuesPageLink = selfHosted
? `${sentryUrl}organizations/${selectedProject.organization.slug}/issues/?project=${selectedProject.id}`
: `https://${selectedProject.organization.slug}.sentry.io/issues/?project=${selectedProject.id}`;

clack.outro(`
${chalk.greenBright("Successfully installed the Sentry Android SDK!")}
${chalk.cyan(
`You can validate your setup by launching your application and checking Sentry issues page afterwards
${issuesPageLink}`,
)}
Check out the SDK documentation for further configuration:
https://docs.sentry.io/platforms/android/
`);
}

//find files with the given extension
function findFilesWithExtensions(
dir: string,
extensions: string[],
filesWithExtensions: string[] = [],
): string[] {
const cwd = process.cwd();
const files = readdirSync(dir, { withFileTypes: true });
for (const file of files) {
if (file.isDirectory()) {
const childDir = path.join(dir, file.name);
findFilesWithExtensions(childDir, extensions, filesWithExtensions);
} else if (extensions.some((ext) => file.name.endsWith(ext))) {
filesWithExtensions.push(path.relative(cwd, path.join(dir, file.name)));
}
}
return filesWithExtensions;
}
Loading
Loading