getsentry / sentry-react-native

Official Sentry SDK for React Native
https://sentry.io
MIT License
1.57k stars 333 forks source link

On install, native iOS SDK is not added to RN<0.60 project #2013

Closed guillaumekh closed 2 years ago

guillaumekh commented 2 years ago

Environment

How do you use Sentry?

Sentry SaaS (sentry.io)

Which SDK and version?

@sentry/react-native 3.2.12 react-native 0.59.10 Xcode 13.2.1 sentry-wizard 1.2.17 sentry-cli 1.71.0

Steps to Reproduce

We follow instructions outlined at https://docs.sentry.io/platforms/react-native/#install

  1. yarn add @sentry/react-native
  2. yarn run react-native link @sentry/react-native
    ✅ Patched build.gradle file.
    ✅ Patched App.js file.
    ✅ Added sentry.properties file to android
    Successfully set up android for react-native
    ✅ Patched build script in Xcode project.
    ✅ Patched App.js file.
    ✅ Added sentry.properties file to ios
    Successfully set up ios for react-native
    🎉  Successfully set up Sentry for your project 🎉
  3. yarn run sentry-wizard -i reactNative -p ios
    Running Sentry Wizard...
    version: 1.2.17 | sentry-cli version: 1.71.0
    Sentry Wizard will help you to configure your project
    Thank you for using Sentry :)
    will not configure android
    will not configure ios
    Skipping connection to Sentry due files already patched
    🎉  Successfully set up Sentry for your project 🎉
  4. cd ios; pod install
    [!] No `Podfile' found in the project directory.
  5. Go to Xcode, press "Run"

Expected Result

Xcode project should build.

Actual Result

Build fails during compilation of RNSentry.m w/ error 'Sentry/Sentry.h' file not found.

The error makes sense since that file is nowhere to be found either in DerivedData or in the project.

Android project builds fine.

Comment

The problem might be linked to the failed pod install, but 2 things make me doubt that:

jennmueng commented 2 years ago

@guillaumekh If you do not have cocoapods, you can do manual linking via: https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#linking-the-native-library

bruno-garcia commented 2 years ago

Sounds like we're missing a note that for RN versions below 0.60, cocoapods isn't installed by default with RN. So unless users installed it manually, sentry-wizard won't be able to install things automatically. So the manual linking step that Jenn mentioned above should help in this case.

We'll make sure to add this note ^ to our docs

guillaumekh commented 2 years ago

i have cocoapods installed and have attempted manual linking too, with the same results.

Is there some additional information I can gather which might be helpful in figuring out what's going on?

guillaumekh commented 2 years ago

i have cocoapods 1.11.2, installed with homebrew (brew install, not brew cask install). This could be related given how many ways there are to install cocoapods.

I'm looking at the sentry-wizard source, and don't see anything related to cocoapods (just grepping for "pod" here). How does sentry-wizard check for it?

jennmueng commented 2 years ago

@guillaumekh react-native link @sentry/react-native is actually what adds the pod to the podfile, looking at the error message you provided:

Unable to find a specification for 'React-Core' depended upon by 'RNSentry'

mind if I can see your whole podfile? Seems like it's missing React-Core

guillaumekh commented 2 years ago

This is starting to make more sense.

I initially had no Podfile, since all my dependencies are installed w/ yarn/npm. I only added a Podfile to satisfy RNSentry's apparent requirement for one. That Podfile only includes the bare minimum:

platform :ios, '9.3'
abstract_target 'allTargets' do
    pod 'RNSentry', :podspec => '../node_modules/@sentry/react-native/RNSentry.podspec'
end
jennmueng commented 2 years ago

@guillaumekh We will fix the docs to link to the manual linking section that cocoapods is actually not required, we didn't link it in the docs at first and used cocoapods as it's included in RN since 0.60.0 and we have since rewrote the docs from scratch.

Anyways, if you choose to continue using cocoapods you will need these other dependencies before RNSentry:

  # React
  pod 'React', :path => '../node_modules/react-native', :subspecs => [
    'Core',
    'CxxBridge',
    'DevSupport',
    'RCTActionSheet',
    'RCTAnimation',
    'RCTBlob',
    'RCTGeolocation',
    'RCTImage',
    'RCTLinkingIOS',
    'RCTNetwork',
    'RCTSettings',
    'RCTText',
    'RCTVibration',
    'RCTWebSocket'
  ]

  pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
  pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
  pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
  pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'

Also, now that you are using cocoapods makesure you open the .xcworkspace file instead of the .xcodeproj file.

guillaumekh commented 2 years ago

This is very helpful thanks.

pod install still fails with the same Unable to find a specification for 'React-Core' error w/ the following Podfile. Any idea what error might be lingering there?

# Uncomment the next line to define a global platform for your project
platform :ios, '9.3'

abstract_target 'allTargets' do
    # Needed for RNSentry because https://github.com/getsentry/sentry-react-native/issues/2013
    pod 'React', :path => '../node_modules/react-native', :subspecs => [
        'Core',
        'CxxBridge',
        'DevSupport',
        'RCTActionSheet',
        'RCTAnimation',
        'RCTBlob',
        'RCTGeolocation',
        'RCTImage',
        'RCTLinkingIOS',
        'RCTNetwork',
        'RCTSettings',
        'RCTText',
        'RCTVibration',
        'RCTWebSocket'
    ]
    pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
    pod 'DoubleConversion', :podspec => '../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec'
    pod 'Folly', :podspec => '../node_modules/react-native/third-party-podspecs/Folly.podspec'
    pod 'glog', :podspec => '../node_modules/react-native/third-party-podspecs/glog.podspec'

    # RNSentry
    pod 'RNSentry', :podspec => '../node_modules/@sentry/react-native/RNSentry.podspec'

    target 'Martini Dev' do
    end
    target 'Martini Staging' do
    end
    target 'Martini Prod' do
    end
end

Anyways, if you choose to continue using cocoapods

I was hoping to avoid cocoapods. If there's a sane way out, I would love to know about it — or alternatively, an older version of RNSentry which plays nicer w/ RN<0.60

jennmueng commented 2 years ago

@guillaumekh I tried your podfile and swapped out the app name for mine and it does not work. Try instead of

abstract_target 'allTargets' do

try

target '<app_name>' do

However, Sentry does not need cocoapods if you do not already use it. It's only a convenience feature as most react native apps should have it installed. Otherwise if you're running into issues and are not familiar with cocoapods it's better you completely remove it and manually link following the guide at https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#linking-the-native-library

guillaumekh commented 2 years ago

I tried your podfile and swapped out the app name for mine and it does not work.

What error are you getting? Wether the pod dependencies are declared in a single abstract_target or duplicated across multiple target is neutral. The problem w/ the configuration you recommend is that the React-Core dependency declared in RNSentry.podspec cannot be satisfied by the React.podspec pulled by npm/yarn and located in ../node_modules/react-native. RNSentry.podspec would need to declare a dependency on React/Core for that to work.

However, Sentry does not need cocoapods if you do not already use it. It's only a convenience feature as most react native apps should have it installed. Otherwise if you're running into issues and are not familiar with cocoapods it's better you completely remove it and manually link following the guide at https://docs.sentry.io/platforms/react-native/manual-setup/manual-setup/#linking-the-native-library

As I said, I have tried manual linking, with identical results ('Sentry/Sentry.h' file not found, because native client is absent).

The RNSentry.xcodeproj has a broken reference to Sentry.xcodeproj, which it expects to find under the path node_modules/@sentry/react-native/ios/Sentry/Sentry.xcodeproj. Since that Sentry.xcodeproj is not an Xcode Product, it is not going to appear on my filesystem unless it's installed by something or someone.

Do I need to add sentry-cocoa myself to the Xcode projet, wether manually or w/ Cocoapods? If so, the docs skip that entirely and should probably be updated.

jennmueng commented 2 years ago

@guillaumekh We removed the manual linking docs as it was our mistake that we removed the reference a while ago and received no reports of it not working. With the React-Core issue, you should downgrade to version 1.8.2 before we changed the dependency. We will explore options of re-adding support for those prior versions or instead bump our minimum requirement.

marandaneto commented 2 years ago

@jennmueng should this issue be closed after release then?

guillaumekh commented 2 years ago

We will explore options of re-adding support for those prior versions or instead bump our minimum requirement.

OK

In the mean time…

For whoever still running RN<0.60 who might stumble on this issue, and until this issue this closed:

jennmueng commented 2 years ago

@guillaumekh Thank you for bringing everything up and writing the guide! I'll add it to our troubleshooting page and possibly a podfile script that'll handle the React-Core issue.