Sentry-react-native: Android build task PreJsAndAssets_SentryUpload fails

Created on 16 Apr 2020  路  6Comments  路  Source: getsentry/sentry-react-native

OS:

  • [ ] Windows
  • [x] MacOS
  • [ ] Linux

Platform:

  • [ ] iOS
  • [x] Android

SDK:

  • [x] @sentry/react-native
  • [ ] react-native-sentry

SDK version: 1.3.7
react-native version: 0.62.2

Are you using Expo?

  • [ ] Yes
  • [x] No

Are you using sentry.io or on-premise?

  • [x] sentry.io (SaaS)
  • [ ] on-premise

Configuration:

Sentry.init({
    dsn:
        'https://[email protected]/1297731',
    environment: appDevMode() ? 'pre-production' : 'production',
    maxValueLength: 5000,
    maxBreadcrumbs: 100
});


I have the following issue:

On build the project using a customized staging flavor, after I migrated react-native to 62.2, it is failing with the following error log:

DEBUG   2020-04-16 13:06:20.119466 -03:00 sentry-cli version: 1.52.1, platform: "darwin", architecture: "x86_64"
INFO    2020-04-16 13:06:20.120082 -03:00 sentry-cli was invoked with the following command line: "/Users/iagor/Desktop/projects/company/rn-59/node_modules/@sentry/cli/sentry-cli" "react-native" "gradle" "--bundle" "/Users/iagor/Desktop/projects/company/rn-59/android/app/build/generated/assets/react/prodMinSdkProdKernel/pre/index.android.bundle" "--sourcemap" "/Users/iagor/Desktop/projects/company/rn-59/android/app/build/generated/sourcemaps/react/prodMinSdkProdKernel/pre/index.android.bundle.map" "--release" "[email protected]+2097407" "--dist" "2097407"
INFO    2020-04-16 13:06:20.120629 -03:00 Issuing a command for Organization: company Project: company
INFO    2020-04-16 13:06:20.120671 -03:00   bundle path: /Users/iagor/Desktop/projects/company/rn-59/android/app/build/generated/assets/react/prodMinSdkProdKernel/pre/index.android.bundle
INFO    2020-04-16 13:06:20.120680 -03:00   sourcemap path: /Users/iagor/Desktop/projects/company/rn-59/android/app/build/generated/sourcemaps/react/prodMinSdkProdKernel/pre/index.android.bundle.map
DEBUG   2020-04-16 13:06:20.120797 -03:00 Non-file bundle found
DEBUG   2020-04-16 13:06:20.120964 -03:00 error: running update nagger
DEBUG   2020-04-16 13:06:20.120983 -03:00 skipping update nagger because session is not attended
error: No such file or directory (os error 2)
DEBUG   2020-04-16 13:06:20.121611 -03:00 client close; no transport to shut down  (from sentry)

FAILURE: Build failed with an exception.

* What went wrong:
    Execution failed for task ':app:bundleProdMinSdkProdKernelPreJsAndAssets_SentryUpload'.
> Process 'command '/Users/iagor/Desktop/projects/company/rn-59/node_modules/@sentry/cli/bin/sentry-cli'' finished with non-zero exit value 1

Steps to reproduce:

  • call react-native run-android --variant prodMinSdkProdKernelPre --appIdSuffix 'pre' (take into account it is a customized flavor)

Actual result:
It fails the build as it can't find the map file.

Expected result:
The Sentry task uploads the source map and finishes build successfully.

Android gradle

Most helpful comment

All 6 comments

When Hermes is enabled, it outputs the map to:

android/app/build/intermediates/sourcemaps/react/prodMinSdkProdKernel/release/index.android.bundle.packager.map

As you can see here it is an index.android.bundle.packager.map and not index.android.bundle.map

On line 56 of react.gradle you can see the execution of the command:

                            commandLine(*execCommand, bundleCommand, "--platform", "android", "--dev", "${devEnabled}",
                                "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir,
                                "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs)

Going to sentry.gradle by replacing:

sourcemapOutput = bundleOutput.replaceAll("(/|\\\\)generated\\1assets\\1react\\1", "\$1generated\$1sourcemaps\$1react\$1") + ".map"

To

sourcemapOutput = bundleOutput.replaceAll("(/|\\\\)generated\\1assets\\1react\\1", "\$1intermediates\$1sourcemaps\$1react\$1") + ".packager.map"

Fixes the issue.

hey @iagormoraes thanks for raising and addressing this.

when running react-native run-android --variant prodMinSdkProdKernelPre --appIdSuffix 'pre' but using react-native < 0.62.2 does it work for you?

What's about skipping --appIdSuffix 'pre'? (using 0.62.2) does it work? just trying to find the root of the problem here.

I really can't find any changes in react-native repo that make the current sentry-react-native to break the build.

hey @iagormoraes thanks for raising and addressing this.

when running react-native run-android --variant prodMinSdkProdKernelPre --appIdSuffix 'pre' but using react-native < 0.62.2 does it work for you?

What's about skipping --appIdSuffix 'pre'? (using 0.62.2) does it work? just trying to find the root of the problem here.

I really can't find any changes in react-native repo that make the current sentry-react-native to break the build.

@marandaneto, I did the testing without the suffix, both release and pre was having problems because Hermes is generating a map file with .packager.map instead of .map, and outputting that on intermediates instead of generated.

As I can see, we are relying on build type, if is hermes or JSC in Sentry.gradle, but the path for RN 62.2 is different.

So I did a patch to fix that:

const fs = require('fs');

try {
    const rootDir = process.cwd();

    const filePath = `${rootDir}/node_modules/@sentry/react-native/sentry.gradle`;
    const pattern = `sourcemapOutput = bundleOutput.replaceAll("(/|\\\\\\\\)generated\\\\1assets\\\\1react\\\\1", "\\$1generated\\$1sourcemaps\\$1react\\$1") + ".map"`;
    const patternFix = `sourcemapOutput = bundleOutput.replaceAll("(/|\\\\\\\\)generated\\\\1assets\\\\1react\\\\1", "\\$1intermediates\\$1sourcemaps\\$1react\\$1") + ".packager.map"`;

    let fileString = fs.readFileSync(filePath, 'utf8');

    fileString = fileString.replace(pattern, patternFix);

    fs.writeFileSync(filePath, fileString, 'utf8');

    console.log('PATCH - Sentry fix.');
} catch (error) {
    console.log(error);
}

hey @iagormoraes got it, I still don't get why the current behavior works on RN 61.x and not on 62.x because I don't find any changes about that on the changelog.
I'd need to test it early next week to be sure that we don't introduce breaking changes on older RN versions, thanks :)

Was this page helpful?
0 / 5 - 0 ratings