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

[Expo EAS] Sourcefiles not getting uploaded only for Android #292

Closed
BrodaNoel opened this issue Oct 15, 2022 · 35 comments
Closed

[Expo EAS] Sourcefiles not getting uploaded only for Android #292

BrodaNoel opened this issue Oct 15, 2022 · 35 comments

Comments

@BrodaNoel
Copy link
Contributor

Summary

For some reason, the sourcemap files are getting uploaded for iOS, and not for Android.

The fact that iOS are working well, kind of confirm me that the configuration is correct.

Screen Shot 2022-10-15 at 11 43 03

Screen Shot 2022-10-15 at 11 43 09

I have:

"expo": "^46.0.0",
"sentry-expo": "~5.0.0",
"@sentry/react-native": "4.2.2",

Then in the app.json:

"plugins": ["sentry-expo"],
"hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "broda-noel",
            "project": "nofilter",
            "authToken": "xxx"
          }
        }
      ]
    },

Managed or bare workflow? If you have ios/ or android/ directories in your project, the answer is bare!

managed

What platform(s) does this occur on?

Android

SDK Version (managed workflow only)

46

Environment

expo-env-info 1.0.5 environment info:
System:
OS: macOS 11.6.1
Shell: 5.8 - /bin/zsh
Binaries:
Node: 16.4.0 - ~/.nvm/versions/node/v16.4.0/bin/node
Yarn: 1.22.19 - ~/.yarn/bin/yarn
npm: 7.18.1 - ~/.nvm/versions/node/v16.4.0/bin/npm
Watchman: 4.9.0 - /usr/local/bin/watchman
Managers:
CocoaPods: 1.11.3 - /usr/local/bin/pod
SDKs:
iOS SDK:
Platforms: iOS 14.5, DriverKit 20.4, macOS 11.3, tvOS 14.5, watchOS 7.4
Android SDK:
API Levels: 27, 31
Build Tools: 23.0.1, 23.0.3, 25.0.3, 26.0.1, 27.0.3, 28.0.3, 29.0.2
System Images: android-31 | Google Play Intel x86 Atom_64
IDEs:
Android Studio: 2021.1 AI-211.7628.21.2111.8309675
Xcode: 12.5.1/12E507 - /usr/bin/xcodebuild
npmPackages:
expo: ^46.0.0 => 46.0.2
react: 18.0.0 => 18.0.0
react-native: 0.69.5 => 0.69.5
npmGlobalPackages:
eas-cli: 2.4.0
expo-cli: 6.0.6
Expo Workflow: managed

Reproducible demo or steps to reproduce from a blank project

I won't be able to create a Snack for this.

@BrodaNoel
Copy link
Contributor Author

I wonder if the _ in the package name (only for android) is breaking something.

@lindesvard
Copy link

lindesvard commented Nov 29, 2022

Having the exact same issue. Works great on iOS.

In Run fastlane I can see Upload Debug Symbols to Sentry
But nothing related to uploading debug symbols in Run gradlew

Dependencies:

sentry-expo@5.0.2
expo@46.0.17
@sentry/react-native@4.2.2

@Norfeldt
Copy link

Norfeldt commented Dec 8, 2022

Is there some way of fixing this until there is a fix from sentry?

tried to run eas update to generate the source map and upload it like

sentry-cli releases files "5.0.0 (69)" upload-sourcemaps --rewrite dist/bundles/android-074b9d283bc01e5f7d6fb080b9bf6cce.map dist/bundles/ios-ad37e2eb59be197c7589139d9e01c3e1.map

This upload it like

Screenshot 2022-12-08 at 14 13 45

but that does not seem to fix it. I also notice that the iOS postPublish upload looks different:

Screenshot 2022-12-08 at 14 14 44

(it does not have a hash in the file name of the map)

@krystofwoldrich
Copy link
Contributor

I was trying to reproduce the error, but sadly no luck.

Here is a repository that step by step (in the commits) adds sentry-expo into a new expo project.

https://github.com/krystofwoldrich/sentry-expo-sample-app

You can try to compare your app to it and maybe we will find a difference or fork the app and add changes that break it in your app and I can debug it.

@fuelkoy
Copy link

fuelkoy commented Jan 16, 2023

Hey @krystofwoldrich, does Sentry show correctly the source map of Sentry.Native.captureException(new Error()); you are throwing? Also I would like to ask that have you run eas update and tried that source maps then work correctly?

EDIT
I downloaded your repo and then tested. And yes the source map shows correctly after initial build. But I went little bit further and noticed that when I make first update to the app and then use sentry-cli to update the source maps dont' work anymore. It seems the source map is being updated with the dist specified in expo-sentry tutorial (https://docs.expo.dev/guides/using-sentry/#uploading-source-maps-for-updates), but the bundle file is not updated with corresponding dist thus resulting coming events not being source mapped. (The 0b bundle file in the image is due I used "jsEngine": "hermes in app.json)

Sieppaa

@krystofwoldrich
Copy link
Contributor

@fuelkoy Thank you for trying it out. From the screenshot, it looks like you uploaded the updated map to the original release. The map name must be index.android.bundle.map, but your updated one is android-6c0d259e381e54ec57d9b286bde31c69.map, so either you would need to create a new release or overwrite the original index.android.bundle.map and index.android.bundle.

@fuelkoy
Copy link

fuelkoy commented Jan 19, 2023

Took my a moment to notice you already answered. But first of all big thank you for helping @krystofwoldrich

I understood from 'Using Sentry - Expo Documentation' that .map file hash is left there by the script:
node_modules/@sentry/cli/bin/sentry-cli releases
files 'release name'
upload-sourcemaps
--dist 'Android Update ID'
--rewrite
dist/bundles/index.android.bundle dist/bundles/android-'hash'.map.

Then my problem is that how is the .bundle file uploaded by eas update? I just tested uploading by (and used index.android.bundle.map, not 'hash') and the script uploads only the .map file, not the bundle file.

Found 1 release file

Analyzing 1 sources
Analyzing completed in 0.021s
Rewriting sources
Rewriting completed in 0.424s
Adding source map references
Bundling files for upload...
Bundling completed in 0.682s
Optimizing completed in 0.025s
Uploading completed in 7.06s
Uploaded release files to Sentry
Processing completed in 0.187s
File upload complete (processing pending on server)
Organization: 'organization'
Project: 'project'
Release: 'release'
Dist: 'Android Update ID'

Source Map Upload Report
Source Maps
~/index.android.bundle.map

I opened issue here and posted a StackOverflow question if someone would know why this is happening, but let me so bold to ask you if you would know.

I'm on Windows and using the following script as the one on Using Sentry - documentation didn't work out of the box. Could this script be the culprit as it doesn't find the index.android.bundle file without specifically putting the file extension ( = index.android.bundle.js)

cross-env ./node_modules/@sentry/cli/bin/sentry-cli releases --org 'organization name' --project 'project name' files 'release name' upload-sourcemaps --dist 'Android Update ID' --rewrite dist/bundles/index.android.bundle dist/bundles/android-'hash'.map

@krystofwoldrich
Copy link
Contributor

Just to clarify the last mentioned command with the index.android.bundle.js did work?

cross-env ./node_modules/@sentry/cli/bin/sentry-cli releases --org 'organization name' --project 'project name' files 'release name' upload-sourcemaps --dist 'Android Update ID' --rewrite dist/bundles/index.android.bundle dist/bundles/android-'hash'.map

Could you post the links to the Expo and Sentry docs you used, and the StackOverflow question?

@fuelkoy
Copy link

fuelkoy commented Jan 19, 2023

I will double check while writing this.
And now after checking yes, with index.android.bundle.js it works, but then on Sentry the artifact will be ~/index.android.bundle.js. And on previous test it didn't recognize as it was not ~/index.android.bundle. (If I understood correctly the problem was because of that naming. I can test this again is needed).
Sieppaa

And of course. Here are the links:
Expo: https://docs.expo.dev/guides/using-sentry/#uploading-source-maps-for-updates
Github issue (with more details than in StackOverflow): #313

EDIT

I now made a new eas update to sentry-expo-sample-app with index.android.bundle.js. And then threw error to see if it is source mapped (dist and release are correct in the event)
Sieppaa2

SOLVED
#313

@RRaideRR
Copy link

RRaideRR commented Mar 21, 2023

I was trying to reproduce the error, but sadly no luck.

Here is a repository that step by step (in the commits) adds sentry-expo into a new expo project.

https://github.com/krystofwoldrich/sentry-expo-sample-app

You can try to compare your app to it and maybe we will find a difference or fork the app and add changes that break it in your app and I can debug it.

just to get it right @krystofwoldrich : this sample project uploads the Android source maps for you during eas build - correct?

I've run the project with the following dependencies and its not uploading:

    "expo": "~48.0.6",
    "expo-status-bar": "~1.4.4",
    "react": "18.2.0",
    "react-native": "0.71.3",
    "sentry-expo": "~6.1.0",
    "expo-application": "~5.1.1",
    "expo-constants": "~14.2.1",
    "expo-device": "~5.2.1",
    "expo-updates": "~0.16.3",
    "@sentry/react-native": "4.13.0"

However: iOS upload works. Two minor things that I changed in comparison to your project:

  • I've made use of the SENTRY_AUTH_TOKEN variable
  • I use my own sentry server.

Thus, my postPublish hook looks like this:

     "hooks": {
      "postPublish": [
        {
          "file": "sentry-expo/upload-sourcemaps",
          "config": {
            "organization": "myOrg",
            "project": "expo-test",
            "url": "https://sentry.myServer.com/"
          }
        }
      ]
    },

@BrodaNoel @lindesvard - did you manage to get it running?

@BrodaNoel
Copy link
Contributor Author

Nop. 'eas build' still not publishing the sourcemaps

@lindesvard
Copy link

lindesvard commented Mar 21, 2023

@RRaideRR sadly not

Edit: have not tried the lastest release tho (6.1.0).

#320 (comment)

@RRaideRR
Copy link

RRaideRR commented Mar 21, 2023

@RRaideRR sadly not

Edit: have not tried the lastest release tho (6.1.0).

#320 (comment)

I've tried it and its not working for my setup :-/. Would be nice if you could also test it on your setup.

@evelant
Copy link

evelant commented Mar 21, 2023

Also seeing this on 6.1.1.

@ldaudet
Copy link

ldaudet commented Mar 24, 2023

Same problem here, it's a big regression from the legacy system, and the docs on the expo website are half updated leading to lots of confusion. Seems like there is no way to get eas build to send the sourcemaps to sentry, but even worse is that I can't even find a way to just get the sourcemaps to upload them myself like we have to do for the eas update.

@CaptainJow
Copy link

I have a similar problem during the build for the apk , I get no errors but during the build proccess I notice that the size of the uploaded files to EAS is smaller that 200kb and that is not logical . and the build APK is just the splash screen

@evelant
Copy link

evelant commented Apr 7, 2023

@brentvatne @kbrandwijk @byCedric @tsapeta Sorry for the notification, but could somebody at Expo bring this to the attention of the appropriate person to get it bumped up in priority? Sentry source maps have been broken on Android when building with EAS for nearly 6 months now. That really limits the usefulness of Sentry and gets in the way of the otherwise stellar experience of using EAS.

If this module is not a priority for active maintenance by Expo perhaps it should be deprecated or spun off into a community repo. As is, it's pretty frustrating to have this "official" Expo integration partially broken for such a long time given that the docs say "Sentry treats React Native as a first-class citizen and we have collaborated with Sentry to make sure Expo is, too.".

Thanks!

@jongbelegen
Copy link

The reason that this happens for me is that the @sentry/react-native version that is being used is 4.13.0.

This version hooks in by using a task that starts with 'bundle',

While in my react native version (0.71.7), I only see the createBundle being ran on build.

It looks like the newer @sentry/react-native did change this behavior. I've been trying to upgrade this package. It did upload a source map but other issues arose.

@krystofwoldrich
Copy link
Contributor

@jongbelegen Exactly like you say.

We added the support for the new RN bundle tasks in 4.14.0 version. Maybe try that instead the major update to v5.

Could you elaborate on what other issues arose? Could you share more in the @sentry/react-native repository?

@giedriusre
Copy link

Sources maps shoud be uploaded automatically while you build app with eas or I need to extra steps for it? Postpublish hooks params I have added in app.json.

@jongbelegen
Copy link

jongbelegen commented Apr 19, 2023

Hi @krystofwoldrich,

When using this branch: https://github.com/jongbelegen/sentry-expo/tree/fix/update-sentry-android-support

I get the following build error:

[RUN_GRADLEW] Source Map Upload Report
[RUN_GRADLEW]   Minified Scripts
[RUN_GRADLEW]     ~/index.android.bundle (sourcemap at index.android.bundle.map)
[RUN_GRADLEW]   Source Maps
[RUN_GRADLEW]     ~/index.android.bundle.map
[RUN_GRADLEW] > Task :app:createBundleReleaseJsAndAssets_SentryCollectModules_com.redacted.app.staging2@2.130.0+embedded_embedded FAILED
[RUN_GRADLEW] node:internal/modules/cjs/loader:1024
[RUN_GRADLEW]   throw err;
[RUN_GRADLEW]   ^
[RUN_GRADLEW] Error: Cannot find module '/private/var/folders/xs/lx_xmc993z183g38nth8zh500000gn/T/eas-build-local-nodejs/03c5a8c7-faae-4d2c-b85f-9134dd055a45/build/redacted-workspace/apps/redacted/node_modules/@sentry/react-native/dist/js/tools/collectModules.js'
[RUN_GRADLEW]     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:1021:15)
[RUN_GRADLEW]     at Function.Module._load (node:internal/modules/cjs/loader:866:27)
[RUN_GRADLEW]     at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
[RUN_GRADLEW]     at node:internal/main/run_main_module:22:47 {
[RUN_GRADLEW]   code: 'MODULE_NOT_FOUND',
[RUN_GRADLEW]   requireStack: []
[RUN_GRADLEW] }
[RUN_GRADLEW] FAILURE: Build completed with 2 failures.
[RUN_GRADLEW] 1: Task failed with an exception.

This probably has to do with using a pnpm monorepo, the package is in the root node_modules and not in de app node_modules.

In my setup I use the custom env variables:

SENTRY_RELEASE=com.redacted.app.staging2@2.130.0
SENTRY_DIST=embedded

When I try to use @sentry/react-native@5.3.1, it builds correctly and the sourcemaps get uploaded for ios and android.

image
(c3b7e303 is the OTA update)

When I trigger an exception it works well on iOS but on android I get the following error on the web ui:

Invalid location in sourcemap (see Troubleshooting for JavaScript)

When running sentry-cli sourcemaps explain 12cd99826cb84c5d9ccfb9d7f5289bbd
I get the following response:

✔ Fetched data for event: 12cd99826cb84c5d9ccfb9d7f5289bbd
✔ Event has release name: com.redacted.app.staging2@2.130.0
✔ Event has a valid exception present
✖ Event exception has no stacktrace available

I also checked my dist for this triggered event and its "embedded".

What would be handy here? Should I make a small reproducable repo using eas build --local with the [@sentry/react-native@5.3.1] dependency?

@krystofwoldrich
Copy link
Contributor

krystofwoldrich commented Apr 25, 2023

@jongbelegen Hi, yes the build error is caused by the mono repo structure, it was fixed in the latter version not to crash the build.
You can adjust the path here: getsentry/sentry-react-native#2740 (comment)

For the Android Stack trace, a minimal reproducible example would help a lot with debugging. A link to a repo or zip would work. :)

@anirudhsama
Copy link

@krystofwoldrich Where should we configure collectModulesScript? In an expo managed app, we cannot modify gradle.properties file right?

@anirudhsama
Copy link

@krystofwoldrich I tried applying the fix by using an expo config, but it still gives the error. Im using this config plugin:

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

// Applying the fix mentioned here https://github.com/getsentry/sentry-react-native/issues/2740

module.exports = (config) => {
	const sentryFix = `project.ext.sentryCli=[collectModulesScript: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../dist/js/tools/collectModules.js")]`;

	return withAppBuildGradle(config, (config) => {
		if (config.modResults.contents.includes("project.ext.sentryCli")) {
			return config;
		}

		config.modResults.contents = config.modResults.contents + "\n" + sentryFix;

		return config;
	});
};

@krystofwoldrich
Copy link
Contributor

@anirudhsama Hi, I'm not familiar with the @expo/config-plugins, so I don't know if the modified fix would work. Would you be able to share an example project?

If you can upgrade to https://github.com/getsentry/sentry-react-native/releases/tag/5.3.1 we fix the build process so it doesn't fail if it can't find the script.

@anirudhsama
Copy link

@expo/config-plugins is a way to modify the app/build.gradle in expo managed workflow. The above code adds the this snippet in app/build.gradle file:

project.ext.sentryCli=[
        collectModulesScript: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../dist/js/tools/collectModules.js")
]

This was required since sentry/react-native is configured in a mono repo and I had to adjust the path of the colletModules.js file, as mentioned here: getsentry/sentry-react-native#2740 (comment).

I will provide a sample project.

Also, this repo (sentry-expo) also uses @expo/config-plugins to provide the integration of sentry/react-native and expo.

@anirudhsama
Copy link

@maximgeerinck
Copy link

maximgeerinck commented May 11, 2023

Can you try putting the sentry fix first?
This worked for me:

I made a plugin (just to make it a bit cleaner):

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

const sentryFix = `project.ext.sentryCli=[collectModulesScript: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../dist/js/tools/collectModules.js")]`;

function withSentryMonorepoFix(config) {
  return withAppBuildGradle(config, config => {
    config.modResults.contents = `
        ${sentryFix}
        ${config.modResults.contents}
    `;
    return config;
  });
}

module.exports = config => withPlugins(config, [withSentryMonorepoFix]);

and made sure this is before sentry-expo in the plugins array in app.json

Next to this i also put a resolution for react-native: "@sentry/react-native": "5.4.2"

@anirudhsama
Copy link

@maximgeerinck Sure, will try this out! Thanks!

@mccraveiro
Copy link

mccraveiro commented May 11, 2023

@maximgeerinck Thanks for the expo-plugin. It fixed the sourcemap upload. However, It's still not working. Got the following error:

There was 1 problem processing this event
Invalid location in sourcemap (see Troubleshooting for JavaScript)

Source app:///index.android.bundle

@mccraveiro
Copy link

mccraveiro commented May 11, 2023

My issue doesn't seem related as It's also happening on iOS builds. I'll move it to a new issue.

Thanks again @maximgeerinck ❤️

@anirudhsama
Copy link

Can you try putting the sentry fix first? This worked for me:

I made a plugin (just to make it a bit cleaner):

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

const sentryFix = `project.ext.sentryCli=[collectModulesScript: new File(["node", "--print", "require.resolve('@sentry/react-native/package.json')"].execute().text.trim(), "../dist/js/tools/collectModules.js")]`;

function withSentryMonorepoFix(config) {
  return withAppBuildGradle(config, config => {
    config.modResults.contents = `
        ${sentryFix}
        ${config.modResults.contents}
    `;
    return config;
  });
}

module.exports = config => withPlugins(config, [withSentryMonorepoFix]);

and made sure this is before sentry-expo in the plugins array in app.json

Next to this i also put a resolution for react-native: "@sentry/react-native": "5.4.2"

Did you have to add any other packages while updating @sentry/react-native to 5.4.2? I'm getting this error after updating it. #332

@celoprd
Copy link

celoprd commented May 16, 2023

My issue doesn't seem related as It's also happening on iOS builds. I'll move it to a new issue.

Thanks again @maximgeerinck ❤️

@mccraveiro Did you find why ? I have the same issue

@mccraveiro
Copy link

@celoprd not yet 😞

I've seen this issue that seems related but I couldn't fix on my project.

@kbrandwijk
Copy link
Contributor

We have released sentry-expo@6.2.0 which includes a version bump of @sentry/react-native that fixes Android build-time sourcemaps uploads. Feel free to open a new issue if you're still seeing issues with Android build-time sourcemap uploads after upgrading sentry-expo and @sentry/react-native.

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

No branches or pull requests