DataDog / expo-datadog

Datadog SDK for Expo
Apache License 2.0
8 stars 5 forks source link

Plugin causes build errors on iOS #34

Closed wongk closed 5 months ago

wongk commented 5 months ago

After following the directions here: https://docs.datadoghq.com/real_user_monitoring/error_tracking/mobile/expo/ and here: https://docs.datadoghq.com/real_user_monitoring/mobile_and_tv_monitoring/setup/expo/#upload-source-maps-on-eas-builds, my iOS builds are now failing with the following error:

[RUN_FASTLANE] ⚠️  Script has ambiguous dependencies causing it to run on every build.
   To fix, go to: Xcode » HealthCoach/HealthCoach » Build Phases » 'Upload dSYMs to Datadog'
   Either: Uncheck "Based on dependency analysis", or select output files to trigger the script

My Expo version is 50.0.17 and my expo-datadog version 50.2.0.

wongk commented 5 months ago

Upgrading to Expo 51 does not resolve this issue.

marco-saia-datadog commented 5 months ago

Hey @wongk!

Can I please ask you to share the complete log from Xcode?

The log you have shared is unrelated and it shouldn't cause the build to fail, since our script is supposed to be ran on every build. I will verify if we can make the warning disappear on our end.

Please double check that:

UPDATE (regarding the warnings)

Even though the warnings are not the cause of your issue, you can get rid of them by unchecking Based on dependency analysis in the Upload dSYMs to Datadog build phase.

Screenshot 2024-05-31 at 12 59 25

Since you might not have direct access to the Xcode project, I have opened a PR in the Xcode parser package that we indirectly use through expo to add the Upload dSYMs to Datadog build phase to the iOS project. If one day it makes it into a release, we should be able to remove the warnings by updating our expo-datadog package.

If you would like to get rid of the warnings, you could apply two patches using patch-package:

expo-datadog+50.2.0.patch

diff --git a/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js b/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
index 67dcd3b..aca7b4c 100644
--- a/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
+++ b/node_modules/expo-datadog/build/plugin/withIosDsyms/withIosDsyms.js
@@ -17,6 +17,7 @@ const withIosDsyms = (config) => {
         xcodeProject.addBuildPhase([], "PBXShellScriptBuildPhase", BUILD_PHASE_NAME, null /* target */, {
             shellScript: `set -e\\n ../node_modules/.bin/datadog-ci dsyms upload $DWARF_DSYM_FOLDER_PATH`,
             shellPath: "/bin/sh",
+            alwaysOutOfDate: true,
         });
         return config;
     });

xcode+3.0.1.patch

diff --git a/node_modules/xcode/lib/pbxProject.js b/node_modules/xcode/lib/pbxProject.js
index 068548a..8f27ab2 100644
--- a/node_modules/xcode/lib/pbxProject.js
+++ b/node_modules/xcode/lib/pbxProject.js
@@ -1644,6 +1644,10 @@ function pbxShellScriptBuildPhaseObj(obj, options, phaseName) {
     obj.shellPath = options.shellPath;
     obj.shellScript = '"' + options.shellScript.replace(/"/g, '\\"') + '"';

+    if (options.alwaysOutOfDate != null) {
+        obj.alwaysOutOfDate = options.alwaysOutOfDate;
+    }
+
     return obj;
 }
wongk commented 5 months ago

It appears that fastlane does not make the full Xcode build log available, but here are the relevant bits from my stdout/err:

[RUN_FASTLANE] › Generating debug HealthCoach » HealthCoach.app.dSYM
[RUN_FASTLANE] › Executing HealthCoach » Bundle React Native code and images
[RUN_FASTLANE] ⚠️  Script has ambiguous dependencies causing it to run on every build.
   To fix, go to: Xcode » HealthCoach/HealthCoach » Build Phases » 'Upload dSYMs to Datadog'
   Either: Uncheck "Based on dependency analysis", or select output files to trigger the script

[RUN_FASTLANE] ▸ ** BUILD FAILED **
[RUN_FASTLANE] ▸ The following build commands failed:
[RUN_FASTLANE] ▸        PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /var/folders/s0/65h138l155b61v3j31k54x300000gn/T/eas-build-local-nodejs/6b1c72d1-108f-42cc-a796-d3b9b70fdd19/build/apps/expo/ios/build/Build/Intermediates.noindex/HealthCoach.build/Release-iphonesimulator/HealthCoach.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'HealthCoach' from project 'HealthCoach')
[RUN_FASTLANE] ▸ (1 failure)
[RUN_FASTLANE] ** BUILD FAILED **
[RUN_FASTLANE] 
[RUN_FASTLANE] 
[RUN_FASTLANE] The following build commands failed:
[RUN_FASTLANE]  PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /var/folders/s0/65h138l155b61v3j31k54x300000gn/T/eas-build-local-nodejs/6b1c72d1-108f-42cc-a796-d3b9b70fdd19/build/apps/expo/ios/build/Build/Intermediates.noindex/HealthCoach.build/Release-iphonesimulator/HealthCoach.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'HealthCoach' from project 'HealthCoach')
[RUN_FASTLANE] (1 failure)
[RUN_FASTLANE] Exit status: 65
[RUN_FASTLANE] 
[RUN_FASTLANE] +---------------------------------------+
[RUN_FASTLANE] |           Build environment           |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] | xcode_path  | /Applications/Xcode.app |
[RUN_FASTLANE] | gym_version | 2.219.0                 |
[RUN_FASTLANE] | sdk         | iPhoneOS17.4.sdk        |
[RUN_FASTLANE] +-------------+-------------------------+
[RUN_FASTLANE] 
[RUN_FASTLANE] Looks like fastlane ran into a build/archive error with your project
[RUN_FASTLANE] It's hard to tell what's causing the error, so we wrote some guides on how
[RUN_FASTLANE] to troubleshoot build and signing issues: https://docs.fastlane.tools/codesigning/getting-started/
[RUN_FASTLANE] Before submitting an issue on GitHub, please follow the guide above and make
[RUN_FASTLANE] sure your project is set up correctly.
[RUN_FASTLANE] fastlane uses `xcodebuild` commands to generate your binary, you can see the
[RUN_FASTLANE] the full commands printed out in yellow in the above log.
[RUN_FASTLANE] Make sure to inspect the output above, as usually you'll find more error information there
[RUN_FASTLANE] 
[RUN_FASTLANE] [!] Error building the application - see the log above
[RUN_FASTLANE] Error: The "Run fastlane" step failed with an unknown error. Refer to "Xcode Logs" below for additional, more detailed logs.

Build failed
The "Run fastlane" step failed with an unknown error. Refer to "Xcode Logs" below for additional, more detailed logs.
npx exited with non-zero code: 1
    Error: build command failed.
marco-saia-datadog commented 5 months ago

Have you checked the points I have mentioned?

Please double check that:

  • @datadog/datadog-ci is installed in your project
  • DATADOG_API_KEY env variable is set correctly on Fastlane
wongk commented 5 months ago

Yep they're good to go.

marco-saia-datadog commented 5 months ago

Is there any way you could provide us with more detailed logs? It is difficult to tell what the problem is without further information.

Does your metro.config.js look like this?

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

const config = {
    transformer: {
      assetPlugins: ['expo-asset/tools/hashAssetFiles'],
      getTransformOptions: async () => ({
        transform: {
          experimentalImportSupport: false,
          inlineRequires: false
        }
      })
    }
  }

  module.exports = mergeConfig(getDefaultConfig(__dirname), config)
wongk commented 5 months ago

I'll see what more logs I can get out of expo. Here is our metro config:

/**
 * @type {import('expo/metro-config')}
 */
const { getDefaultConfig } = require('@expo/metro-config')
const path = require('path')

const projectRoot = __dirname
const workspaceRoot = path.resolve(__dirname, '../..')

const config = getDefaultConfig(projectRoot)

config.watchFolders = [workspaceRoot]
config.resolver.nodeModulesPaths = [
  path.resolve(projectRoot, 'node_modules'),
  path.resolve(workspaceRoot, 'node_modules'),
]
config.resolver.blockList = [new RegExp(`${workspaceRoot}/ref/takeout`)]

config.transformer = { ...config.transformer, unstable_allowRequireContext: true }
config.transformer.minifierPath = require.resolve('metro-minify-terser')

module.exports = config
wongk commented 5 months ago

I was not able to get Xcode logs when running an EAS build locally, but I was finally able to get them when running on EAS cloud. Here is the actual error message: /Users/expo/Library/Developer/Xcode/DerivedData/HealthCoach-cadkgkgehnezpjdtijikapiciihy/Build/Intermediates.noindex/ArchiveIntermediates/HealthCoach/IntermediateBuildFilesPath/HealthCoach.build/Release-iphoneos/HealthCoach.build/Script-00DD1BFF1BD5951E006B06BC.sh: line 41: ../node_modules/.bin/datadog-ci: No such file or directory.

In our case (tamagui project, monorepo using yarn workspaces), this relative path is incorrect. The datadog-ci binary is actually up two more levels in the root node_modules directory. Can you update the script to use npx datadog-ci? This would be the most flexible approach.

lolJS commented 5 months ago

We have the same issue in our project using turbo repo

marco-saia-datadog commented 5 months ago

Hi @wongk

We are addressing this issue in this PR: https://github.com/DataDog/expo-datadog/pull/38.

Can you confirm that the binary is located in node_modules/.bin/datadog-ci?

From my understanding, the relative path is currently failing to locate node_modules as the script is executed from two levels up in your setup, correct?

wongk commented 5 months ago

Thanks for the update Marco. I am including the screenshot below which shows the relevant parts of our project structure.

Screenshot 2024-06-11 at 12 58 48 PM

wongk commented 5 months ago

@marco-saia-datadog I have confirmed that this issue is resolved for iOS. Thank you!

However, the issue also exists for Android.

FAILURE:
Build failed with an exception.
* What went wrong:
Execution failed for task ':app:uploadReleaseSourcemaps'.
> A problem occurred starting process 'command '/home/expo/workingdir/build/apps/expo/node_modules/.bin/datadog-ci''
marco-saia-datadog commented 5 months ago

Hi @wongk! Have you updated our SDK to the latest version?

wongk commented 5 months ago

I sure have. That's how I confirmed it's working for iOS.

marco-saia-datadog commented 5 months ago

The reason why I am asking is because the iOS fix is contained in the new Expo release, while the Android fix is contained in the SDK release (@datadog/mobile-react-native package) in v2.3.6.

If you have verified that the fix does not work, even after cleaning up your project and using the latest release, you can temporarily set the DATADOG_CI_EXEC env variable to point to your datadog-ci executable, and this should unblock you in the meantime.

wongk commented 5 months ago

Got it. It wasn't clear to me that you were referring to the react native SDK and not the expo-datadog plugin. I did not click the link.

I will give that a shot.

wongk commented 5 months ago

Confirmed no build errors on Android after updating the SDK version. Thank you!

marco-saia-datadog commented 5 months ago

Perfect! Glad I could help 😃

seanadkinson commented 4 months ago

I was not able to get Xcode logs when running an EAS build locally, but I was finally able to get them when running on EAS cloud. Here is the actual error message:

@wongk , how did you get the more detailed error message on EAS cloud? I am also receiving this error:

▸ ** BUILD FAILED **
▸ The following build commands failed:
▸   PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/workingdir/build/ios/build/Build/Intermediates.noindex/sltapp.build/Release-iphonesimulator/sltapp.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'sltapp' from project 'sltapp')
▸ (1 failure)
** BUILD FAILED **
The following build commands failed:
    PhaseScriptExecution Bundle\ React\ Native\ code\ and\ images /Users/expo/workingdir/build/ios/build/Build/Intermediates.noindex/sltapp.build/Release-iphonesimulator/sltapp.build/Script-00DD1BFF1BD5951E006B06BC.sh (in target 'sltapp' from project 'sltapp')
(1 failure)

Exit status: 65

But I can't seem to figure out what the underlying error is.

My hunch is that it isn't picking up DATADOG_API_KEY from EAS Secrets, but I'm unable to confirm yet.

seanadkinson commented 4 months ago

Well, it says it pretty loud and clear, but still I was missing it 🤦 . Maybe this will help others... you can download the Xcode Logs in the separate section below the build logs, at the bottom of the screenshot below.

FWIW, in my case, I had an await DdSdkReactNative.initialize(config); at the top-level of a datadog.ts file (due to copy/paste from datadog docs), and that was causing an error at this step only, but not when running locally, or any other time that I could tell. A bit stumped about that still, but moving on...

Screenshot 2024-07-11 at 4 29 07 AM