sentry-react-native icon indicating copy to clipboard operation
sentry-react-native copied to clipboard

Sentry requires `'APPLICATION_EXTENSION_API_ONLY=YES`

Open Mitch528 opened this issue 1 year ago • 19 comments

OS:

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

Platform:

  • [x] iOS
  • [ ] Android

SDK:

  • [x] @sentry/react-native (>= 1.0.0)
  • [ ] react-native-sentry (<= 0.43.2)

SDK version: 5.24.1

react-native version: 0.74.2

Are you using Expo?

  • [ ] Yes
  • [x] No

Are you using sentry.io or on-premise?

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

I have the following issue:

Build fails with:

SentryProfilerState.mm

Property 'date' cannot be found in forward class object 'SentryCurrentDateProvider'

This is also on Xcode 16.0 Beta, so I'm not sure if it's related or not to #3883

Actual result:

Build fails

Expected result:

Build does not fail.

Mitch528 avatar Jun 20 '24 16:06 Mitch528

Hi @Mitch528, thank you for the report, we'll check it.

Are your pods up to date, are you using the 'Sentry/HybridSDK', '8.29.1'? Just want to confirm this since workaround for https://github.com/getsentry/sentry-react-native/issues/3883 was changing manually the Sentry pod version.

krystofwoldrich avatar Jun 21 '24 07:06 krystofwoldrich

Hi @krystofwoldrich yeah, pods are up-to-date. I've tried regenerating my Podfile.lock without luck as well.

I didn't explicitly include the pod in my Podfile but it does seem like it's included in the lockfile:

  - RNSentry (5.24.1):
    - hermes-engine
    - React-Core
    - React-hermes
    - Sentry/HybridSDK (= 8.29.1)
...
  - Sentry/HybridSDK (8.29.1)

Mitch528 avatar Jun 21 '24 15:06 Mitch528

@Mitch528 Thanks for the details.

krystofwoldrich avatar Jun 25 '24 07:06 krystofwoldrich

I'm seeing this same issue issue Xcode 16 beta 3

zdtclement avatar Jul 18 '24 17:07 zdtclement

Hi @zdtclement, thank you for the message, what version of the SDK are you using?

Are you running Xcode 16 on Sonoma or beta of Sequoia?

krystofwoldrich avatar Aug 01 '24 12:08 krystofwoldrich

Hello everyone we have tested the Xcode 16 Beta 4 and RN 73 and could not reproduce the issue.

If the build is failing for you, could you share a minimal reproducible sample which we can debug?

krystofwoldrich avatar Aug 02 '24 14:08 krystofwoldrich

Hello everyone we have tested the Xcode 16 Beta 4 and RN 73 and could not reproduce the issue.

If the build is failing for you, could you share a minimal reproducible sample which we can debug?

@krystofwoldrich

I found out why the build was failing for me. I had this in my Podfile in order to fix a OneSignal related issue.

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
    end

Changing it to the following resolves the issue for me:

  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if target.name != "Sentry"
        config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
      end
    end

Mitch528 avatar Aug 02 '24 15:08 Mitch528

@Mitch528 Thank you for the message!

krystofwoldrich avatar Aug 02 '24 16:08 krystofwoldrich

We should add information about APPLICATION_EXTENSION_API_ONLY to the docs (RN manual setup on iOS, troubleshooting).

krystofwoldrich avatar Aug 09 '24 12:08 krystofwoldrich

added to troubleshooting docs in https://github.com/getsentry/sentry-docs/pull/10087

kahest avatar Sep 18 '24 15:09 kahest

After adding the above changes in my podFile. https://github.com/getsentry/sentry-react-native/issues/3908#issuecomment-2265703635

post_install do |installer|
  config = use_native_modules!
  installer.pods_project.targets.each do |target|
	target.build_configurations.each do |config|
	  if target.name != "Sentry"
		config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
	  end
	end
  end
  # https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
  react_native_post_install(
    installer,
    config[:reactNativePath],
    :mac_catalyst_enabled => false
  )
end

I keep on getting this error. Any one know how to fix this.

unexpected service error: The Xcode build system has crashed. Build again to continue.

adityakmr7 avatar Sep 19 '24 09:09 adityakmr7

@adityakmr7 I'm not sure this is related - did you cleaning build caches, derived data, etc.? Which version of macOS/Xcode are you using?

kahest avatar Sep 20 '24 13:09 kahest

@adityakmr7 Have you used APPLICATION_EXTENSION_API_ONLY before? We recommend to explicitly set it to YES for Sentry at the end of the post install scripts.

More at: https://docs.sentry.io/platforms/react-native/troubleshooting/#unknown-receiver-somereceiver-use-of-undeclared-identifier-someidentifier

krystofwoldrich avatar Sep 30 '24 13:09 krystofwoldrich

Can we remove the need of APPLICATION_EXTENSION_API_ONLY=YES from sentry-cocoa?

krystofwoldrich avatar Oct 04 '24 11:10 krystofwoldrich

For reference https://developer.apple.com/documentation/xcode/build-settings-reference#Require-Only-App-Extension-Safe-API

krystofwoldrich avatar Oct 04 '24 12:10 krystofwoldrich

target.build_configurations.each do |config|
	  if target.name != "Sentry"
		config.build_settings['APPLICATION_EXTENSION_API_ONLY'] = 'NO'
	  end
	end

This worked cool ! thanks

ref : https://github.com/getsentry/sentry-react-native/issues/3908#issuecomment-2265703635

sahad00 avatar Oct 09 '24 13:10 sahad00

Thank you for the message @sahad00.

Could you share a bit more details why you set ['APPLICATION_EXTENSION_API_ONLY'] = 'NO' for all other targets?

krystofwoldrich avatar Oct 10 '24 14:10 krystofwoldrich

It looks like they are some libraries like the following, which change this values for all targets.

I don't mean to point to any particular library just adding here samples I've found to help us understand why our Sentry lib is encountering this issue.

  • https://github.com/gitn00b1337/expo-widgets/blob/82042df354823db7dac6bbf73c890d63ae2e00f1/plugin/src/ios/withPodfile.ts#L56
  • https://github.com/bndkt/react-native-widget-extension/blob/ee9d8974831025fa888868c38b4244529d58e428/plugin/src/withPodfile.ts#L38
  • https://github.com/relateddigital/react-native-related-digital/blob/66dbac8a989f355f2caa9ca4b630024a93df27fc/README.md?plain=1#L327

krystofwoldrich avatar Oct 10 '24 14:10 krystofwoldrich

  • https://forums.swift.org/t/set-application-extension-api-only-on-a-spm-package/39333/57
  • https://stackoverflow.com/questions/67494911/unable-to-compile-react-native-share-extension-ios-12-5

krystofwoldrich avatar Oct 11 '24 12:10 krystofwoldrich

By setting APPLICATION_EXTENSION_API_ONLY to YES, we ensure our library is extension-safe, meaning it doesn’t use any APIs prohibited in app extensions. This is typically expected of libraries to maintain broad compatibility. Setting APPLICATION_EXTENSION_API_ONLY = YES in our library’s pod_target_xcconfig is considered a good practice to ensure that any code within your library will work in both app and extension contexts without imposing restrictions on the app itself.

My understanding is that the need for the troubleshooting workaround on Cocoa and React Native is due to a CocoaPods issue (other related issues)propagating the change to the host application.

There are libraries that do not adopt this restriction. For example Firebase does not use the APPLICATION_EXTENSION_API_ONLY apart from SwiftLint (Crashlytics does not set the flag) . What they do is marking methods that are unavailable in extensions with NS_EXTENSION_UNAVAILABLE_IOS, NS_EXTENSION_UNAVAILABLE or @available(*ApplicationExtension, unavailable) in Swift.

Can we remove the need of APPLICATION_EXTENSION_API_ONLY=YES from sentry-cocoa?

I think we should keep the option to ensure compatibility with extensions on Cocoa and React Native. If we decide to drop the option we may use lint or static analysis tools to enforce the api restrictions.

antonis avatar Oct 25 '24 15:10 antonis

Yes, make sense to keep it to stay compatible with app extensions.

But I think if possible we should be able to compile also with the flag set to NO.

What confuses me is that the Cocoa SDK only compiles with the flag set to YES.

If this flag only limits the API set I would expect the code also compile without it.

krystofwoldrich avatar Oct 28 '24 16:10 krystofwoldrich

Image

After Installing Xcode16 and with Mac chip M1 Pro and react native versions "0.72.4" and "@sentry/react-native": "^6.1.0", I'm getting this error building.

Command SwiftVerifyEmittedModuleInterface failed with a nonzero exit code

iamthemuhammadirfan avatar Nov 01 '24 03:11 iamthemuhammadirfan

Thank you for reporting @iamthemuhammadirfan 🙇 Does the issue still occur after clearing all build caches including derived data? Is the issue related with the APPLICATION_EXTENSION_API_ONLY build setting? If not, please consider opening a separate issue with more details and we will be glad to continue the investigation there 🙇

antonis avatar Nov 01 '24 08:11 antonis

I've opened a PR with a possible work around for this issue https://github.com/getsentry/sentry-cocoa/pull/4599

antonis avatar Dec 04 '24 16:12 antonis

After is merged this Issue will be closed.

https://github.com/getsentry/sentry-cocoa/pull/4603

https://github.com/getsentry/sentry-cocoa/pull/4603 adds a clear error message about the missconfigured flag.

Sentry Cocoa needs the flag to work/build correctly.

krystofwoldrich avatar Dec 10 '24 13:12 krystofwoldrich

Closing since https://github.com/getsentry/sentry-cocoa/pull/4603 is merged 🎉

antonis avatar Dec 13 '24 11:12 antonis