Skip to content

fix: make the opt-in SPM path build and launch - #334

Merged
diegomtz5 merged 1 commit into
mainfrom
fix-spm-opt-in
Oct 22, 2026
Merged

diegomtz5 merged 1 commit into
mainfrom
fix-spm-opt-in

Conversation

@diegomtz5

Copy link
Copy Markdown
Contributor

What & why

The opt-in Swift Package Manager path (NEWRELIC_USE_SPM=1, added in #313) didn't work. An app that opted in failed at the first of these:

  1. Xcode crashed resolving the package. The podspec passed sdkVersions.ios to SPM as an exact version. Since 1.9.0 (chore: Update native agents to v1.9.0 #315) that value is a CocoaPods requirement such as ~>7.7.8, and Xcode fails on it: non-numerical characters in version core identifier '~>7'.
  2. The app crashed at launch. React Native's spm_dependency links the pod against NewRelic.xcframework, but nothing embeds that dynamic framework in the app: dyld: Library not loaded: @rpath/NewRelic.framework/NewRelic. Xcode 26+ archives also failed on a duplicate NewRelic.xcframework-ios.signature.

React Native fixes the second problem upstream in react/react-native#58781, which no released version has yet (0.86 and earlier).

Changes

  • newrelic-react-native-agent.podspec: the SPM requirement is now upToNextMinorVersion from the version in sdkVersions.ios. That's the SPM equivalent of CocoaPods' ~> (~> 7.7.8 means ≥ 7.7.8 and < 7.8.0).

  • newrelic_spm.rb (new, loaded by the podspec), in SPM mode only:

    • adds install_spm_framework "NewRelic" to each app's [CP] Embed Pods Frameworks script, using the same shell function as #58781;
    • removes the pod's duplicate xcframework signature;
    • steps aside when React Native already embeds the framework.

    CocoaPods regenerates that script on every install, so apps need no Podfile changes, the app's .xcodeproj is never edited, and turning SPM off leaves nothing behind. The approach follows stripe-react-native's stripe_spm.rb.

  • NewRelicExampleApp-SPM/README.md: the "is SPM active" check now includes the embed call and an actual launch. The old check passed while the app crashed.

Testing

On NewRelicExampleApp-SPM (React Native 0.76.5, Xcode 27.1, CocoaPods 1.16.2), with this branch as the plugin:

Check Before After
xcodebuild -resolvePackageDependencies crash ('~>7') resolves NewRelic 7.7.9
Debug simulator build + launch launch crash (Library not loaded) NewRelic.framework 7.7.9 embedded, launches
Release simulator build + launch launch crash embedded, launches, [NRMA] React Native agent started.
xcodebuild archive fails on the duplicate signature succeeds, framework embedded
Second pod install — no change
SPM turned off — embed call gone, NewRelicAgent 7.7.8 from CocoaPods as before

Not tested: a physical device, other React Native versions, and the new architecture.

Note: with upToNextMinorVersion, SPM apps already get iOS agent 7.7.9. It's on GitHub and SPM but not yet on CocoaPods, where the default path still reads from.

Release note

Fixed the opt-in Swift Package Manager integration (NEWRELIC_USE_SPM=1): apps no longer crash at launch with Library not loaded: @rpath/NewRelic.framework/NewRelic, archives no longer fail on a duplicate xcframework signature, and the iOS agent resolves to the newest 7.7.x release.

🤖 Generated with Claude Code

Two bugs kept NEWRELIC_USE_SPM=1 apps from working:

- The podspec passed sdkVersions.ios (a CocoaPods requirement such as '~>7.7.8' since 1.9.0) to SPM as an exact version; Xcode crashes resolving it. It now uses upToNextMinorVersion from that version, the SPM equivalent of '~>'.
- React Native's spm_dependency links the pod against NewRelic.xcframework but never embeds the dynamic framework, so the app crashed at launch (Library not loaded: @rpath/NewRelic.framework/NewRelic), and Xcode 26+ archives failed on a duplicate xcframework signature. newrelic_spm.rb adds NewRelic.framework to the app's [CP] Embed Pods Frameworks script and removes the duplicate signature, as react/react-native#58781 does in unreleased React Native; it steps aside when React Native already does it.

Verified on the SPM example (RN 0.76.5, Xcode 27.1): Debug and Release simulator builds embed NewRelic.framework 7.7.9 and launch with the agent started, the archive succeeds, a second pod install changes nothing, the app's .xcodeproj is never edited, and turning SPM off removes the embed call.
@diegomtz5 diegomtz5 added the release-note:bug Release notes: Bug fixes label Oct 22, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Release notes check: passed

This PR will appear under Bug fixes (from its label) as:

Fixed the opt-in Swift Package Manager integration (NEWRELIC_USE_SPM=1): apps no longer crash at launch with Library not loaded: @​rpath/NewRelic.framework/NewRelic, archives no longer fail on a duplicate xcframework signature, and the iOS agent resolves to the newest 7.7.x release.

Release notes are reviewed and edited by a person before they are published.

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.25%. Comparing base (d1f9db4) to head (0166991).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #334   +/-   ##
=======================================
  Coverage   89.25%   89.25%           
=======================================
  Files          12       12           
  Lines         484      484           
  Branches      103      103           
=======================================
  Hits          432      432           
  Misses         46       46           
  Partials        6        6           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@diegomtz5
diegomtz5 merged commit 3a7e11b into main Oct 22, 2026
10 checks passed
@ndesai-newrelic
ndesai-newrelic deleted the fix-spm-opt-in branch October 30, 2026 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-note:bug Release notes: Bug fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants