Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proguard Mappings are not uploaded using expo plugin #4400

Open
rtorrente opened this issue Dec 22, 2024 · 6 comments · May be fixed by #4440
Open

Proguard Mappings are not uploaded using expo plugin #4400

rtorrente opened this issue Dec 22, 2024 · 6 comments · May be fixed by #4440

Comments

@rtorrente
Copy link

What React Native libraries do you use?

React Navigation, Hermes, Expo Application Services (EAS), Expo (mobile only)

Are you using sentry.io or on-premise?

sentry.io (SaS)

@sentry/react-native SDK Version

6.3.0

How does your development environment look like?

expo-env-info 1.2.1 environment info:
System:
OS: macOS 15.2
Shell: 5.9 - /bin/zsh
Binaries:
Node: 20.12.0 - ~/.nvm/versions/node/v20.12.0/bin/node
npm: 10.5.0 - ~/.nvm/versions/node/v20.12.0/bin/npm
Managers:
CocoaPods: 1.16.2 - /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms: DriverKit 24.2, iOS 18.2, macOS 15.2, tvOS 18.2, visionOS 2.2, watchOS 11.2
IDEs:
Xcode: 16.2/16C5032a - /usr/bin/xcodebuild
npmPackages:
expo: ~52.0.20 => 52.0.20
react: 18.3.1 => 18.3.1
react-native: 0.76.5 => 0.76.5
Expo Workflow: managed
New arch : disabled
Hermes: Enabled

Sentry.init()

  Sentry.init({
    dsn: SENTRY_CONFIG.DSN,
    debug: false,
    environment: SENTRY_CONFIG.environment,
    autoSessionTracking: true,
    attachScreenshot: true,
    attachStacktrace: true,
    tracesSampleRate: SENTRY_CONFIG.tracesSampleRate,
    tracePropagationTargets: [
      APP_CONFIG.WP_URL,
    ],
    integrations: [navigationIntegration],
  });

And config on app.json expo

    [
      "@sentry/react-native/expo",
      {
        organization: "ORG",
        project: process.env.SENTRY_PROJECT_NAME,
        url: "https://sentry.io",
      },
    ],

Steps to Reproduce

1 : Enable R8 and Proguard using expo-build-properties plugin

Config look like :

[
      "expo-build-properties",
      {
        android: {
          enableProguardInReleaseBuilds: true,
          enableShrinkResourcesInReleaseBuilds: true,
        },
        ios: {
          useFrameworks: "static",
        },
      },
],

2 : Build with EAS for android

Expected Result

Proguard mapping are uploaded on Sentry

Actual Result

Source maps are uploaded but proguard mapping aren't uploaded.
So on issue, there is a "Unminify code" button

@antonis
Copy link
Collaborator

antonis commented Dec 23, 2024

Hello @rtorrente 👋
You can use Sentry's Gradle integration to upload the Android ProGuard mapping files. Please check the Sentry Android Gradle Plugin documentation for more information on this.
Let us know if that helps 🙏

Also please note that we're winding down for the holidays, so responses will be slower than usual.

@rtorrente
Copy link
Author

Hey @antonis,
Thanks for your reply, the Android gradle Plugin is not included automaticaly when we add the @sentry/react-native/expo plugin in expo app.json ?

The problem is that we don't have direct access to gradle file with expo and expo config plugin are used for that

@getsantry getsantry bot moved this from Waiting for: Community to Waiting for: Product Owner in GitHub Issues with 👀 3 Dec 23, 2024
@antonis
Copy link
Collaborator

antonis commented Dec 23, 2024

Thank you for your response @rtorrente 🙇

We will investigate this further and iterate back. Since you cannot directly access the Gradle file to add the Android Gradle Plugin, I would suggest manually uploading the mapping files as a workaround.

@antonis
Copy link
Collaborator

antonis commented Jan 13, 2025

Thank you for your patience @rtorrente 🙇

We will investigate this further and iterate back. Since you cannot directly access the Gradle file to add the Android Gradle Plugin

One solution to add the Sentry Android Gradle Plugin (SAGP) is to add a custom Expo plugin in your app.json like:

{
  "expo": {
    "plugins": [
        ["./withSentryAndroidGradlePlugin",
          {
            "version": "4.14.1",
            "uploadNativeSymbols": true,
            "includeNativeSources": true,
            "autoInstallationEnabled": false
          }
        ]
      ]
  }
}

The custom plugin implemented in withSentryAndroidGradlePlugin.js modifies your Gradle files and installs SAGP

example implementation

const {
  withAppBuildGradle,
  withProjectBuildGradle,
} = require("@expo/config-plugins");

module.exports = function withSentryAndroidGradlePlugin(config, options = {}) {
  const version = options.version || "4.14.1";
  const uploadNativeSymbols = options.uploadNativeSymbols ?? true;
  const includeNativeSources = options.includeNativeSources ?? true;
  const autoInstallationEnabled = options.autoInstallationEnabled ?? false;

  // Modify android/build.gradle
  const withSentryProjectBuildGradle = (config) => {
    return withProjectBuildGradle(config, (projectBuildGradle) => {
      if (
        !projectBuildGradle.modResults ||
        !projectBuildGradle.modResults.contents
      ) {
        throw new Error(
          "android/build.gradle content is missing or undefined."
        );
      }

      const dependency = `classpath("io.sentry:sentry-android-gradle-plugin:${version}")`;

      if (!projectBuildGradle.modResults.contents.includes(dependency)) {
        projectBuildGradle.modResults.contents =
          projectBuildGradle.modResults.contents.replace(
            /dependencies\s*{/,
            `dependencies {\n        ${dependency}`
          );
      }

      return projectBuildGradle;
    });
  };

  // Modify android/app/build.gradle
  const withSentryAppBuildGradle = (config) => {
    return withAppBuildGradle(config, (config) => {
      if (config.modResults.language === "groovy") {
        const sentryPlugin = `apply plugin: "io.sentry.android.gradle"`;
        const sentryConfig = `
  sentry {
      uploadNativeSymbols = ${uploadNativeSymbols}
      includeNativeSources = ${includeNativeSources}
      autoInstallation {
          enabled = ${autoInstallationEnabled}
      }
  }`;

        let contents = config.modResults.contents;

        if (!contents.includes(sentryPlugin)) {
          contents = `${sentryPlugin}\n${contents}`;
        }

        if (!contents.includes("sentry {")) {
          contents = `${contents}\n${sentryConfig}`;
        }

        config.modResults.contents = contents;
      } else {
        throw new Error(
          "Cannot configure Sentry in android/app/build.gradle because it is not in Groovy."
        );
      }
      return config;
    });
  };

  config = withSentryProjectBuildGradle(config);
  config = withSentryAppBuildGradle(config);

  return config;
};

Note that we are planning to include this as a feature in the future.

@antonis antonis linked a pull request Jan 13, 2025 that will close this issue
10 tasks
@rtorrente
Copy link
Author

rtorrente commented Jan 13, 2025

Hi @antonis,

Thanks for the plugin code, it works very well.

I just had to add the autoUploadProguardMapping property in your code to disable proguard upload in the build of an PR/MR for example, where I don't have a SENTRY_TOKEN in this context.

Here is the new sentryConfig

const sentryConfig = `
  sentry {
      autoUploadProguardMapping = ${autoUploadProguardMapping}
      uploadNativeSymbols = ${uploadNativeSymbols}
      includeNativeSources = ${includeNativeSources}
      autoInstallation {
          enabled = ${autoInstallationEnabled}
      }
  }`;

It works well

Hope to see this merged directly in the default expo plugin to be usable by other people.

Thanks you again!

@getsantry getsantry bot moved this to Waiting for: Product Owner in GitHub Issues with 👀 3 Jan 13, 2025
@antonis
Copy link
Collaborator

antonis commented Jan 14, 2025

I just had to add the autoUploadProguardMapping property in your code to disable proguard upload

Thank you for the prompt feedback @rtorrente 🙇
It makes sense to include the autoUploadProguardMapping in the available options.

@antonis antonis self-assigned this Jan 14, 2025
@antonis antonis moved this from Backlog to In Progress in Mobile & Cross Platform SDK Jan 14, 2025
@antonis antonis moved this from In Progress to Needs Review in Mobile & Cross Platform SDK Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Status: Needs Review
Development

Successfully merging a pull request may close this issue.

3 participants