OneSignal / react-native-onesignal

React Native Library for OneSignal Push Notifications Service
Other
1.56k stars 373 forks source link

[Bug]: OneSignal/OneSignal.h file not found #1440

Closed brunoleitem closed 11 months ago

brunoleitem commented 1 year ago

What happened?

Hello, im currently trying to do Archive on my XCode and failing with Lexical or Preprocessor Issue => OneSignal/OneSignal.h file not found

Already tried reinstalling pods and creating a new notifications extension following the installation guide.

Steps to reproduce?

XCode 13
IOS 13
React Native 0.63.4

Steps on XCode
1. Clean build
2. Archive

What did you expect to happen?

I expected to complete the xcode archive.

React Native OneSignal SDK version

4.3.3

Which platform(s) are affected?

Relevant log output

No response

Code of Conduct

jayshah123 commented 1 year ago

Facing same issue with following environment:

System:
    OS: macOS 12.5
    CPU: (10) arm64 Apple M1 Pro
    Memory: 124.86 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.17.1 - ~/.nvm/versions/node/v16.17.1/bin/node
    Yarn: 1.18.0 - ~/.nvm/versions/node/v16.17.1/bin/yarn
    npm: 8.18.0 - ~/Documents/rippling-mobile/node_modules/.bin/npm
    Watchman: 2022.10.03.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.0.1/14A400 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.11 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.68.2 => 0.68.2 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

react-native-onesignal version according to yarn.lock:

react-native-onesignal@4.4.0:
     resolved "https://registry.yarnpkg.com/react-native-onesignal/-/react-native-onesignal-4.4.0.tgz#731651bf074bac7d5e1576e8670a5850aacce362"

Onesignal contents in Podfile.lock:

  - OneSignalXCFramework (3.11.2):
    - OneSignalXCFramework/OneSignalCore (= 3.11.2)
    - OneSignalXCFramework/OneSignalExtension (= 3.11.2)
    - OneSignalXCFramework/OneSignalOutcomes (= 3.11.2)
  - OneSignalXCFramework/OneSignalCore (3.11.2)
  - OneSignalXCFramework/OneSignalExtension (3.11.2):
    - OneSignalXCFramework/OneSignalCore
    - OneSignalXCFramework/OneSignalOutcomes
  - OneSignalXCFramework/OneSignalOutcomes (3.11.2):
    - OneSignalXCFramework/OneSignalCore
jedi2209 commented 1 year ago

Have the same problem, but on a different package version. react-native-onesignal@^4.4.1

The environment is the same:

jayshah123 commented 1 year ago

I see this in Debug builds and not on Release configuration, e.g. react-native run-ios will break.

hinh-eoh commented 1 year ago

Facing the same issue with Xcode 14, but can achieve success.

kingkongqn4444 commented 1 year ago

the same issuse

jayshah123 commented 1 year ago

The solution seems to be: If you are excluding arm64 via excluded architechtures build setting, Make sure it is excluded for all targets (even the pods project).

After doing the above, error should not appear.

pingkungjaza commented 1 year ago

OneSignal/OneSignal.h is in https://documentation.onesignal.com/docs/react-native-sdk-setup

Please see "Manually updating iOS OneSignalNativeSDK" above step 6. Then download "Source code" and do the step in manually.

pingkungjaza commented 1 year ago

[Update] If you install all of package. then you open file.xcworkspace and build It's work for me.

! file.xcodeproj has some bug

Dajust commented 1 year ago

rm -rf node_modules pod deintegrate yarn pod install

Fixed for me!

gorkemogut commented 1 year ago

Xcode 15.0 beta 3 has same problem with M2 Mac

Mr-Anonymous commented 1 year ago

Has anyone found any solution for this? I get the same error: 'OneSignal/OneSignal.h' file not found

kamaravichow commented 1 year ago

I think the documentation was updated and needs to be updated to OneSignalFramework/OneSignalFramework.h

killerchip commented 11 months ago

I am having the same issue. I use latest Expo (SDK 49.0.0), and we have tweaked the `onesignal-expo-config' to add to podFile:

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
end`;

I can see it installs:

[INSTALL_PODS] Installing react-native-onesignal (5.0.0)
[INSTALL_PODS] Installing OneSignalXCFramework (5.0.1)

But when fastlane is run I get the dreaded:

(ios/OneSignalNotificationServiceExtension/NotificationService.m:1:9)

> 1 | #import <OneSignal/OneSignal.h>
    |         ^ 'OneSignal/OneSignal.h' file not found

Any idea?

aindong commented 11 months ago

I am having the same issue. I use latest Expo (SDK 49.0.0), and we have tweaked the `onesignal-expo-config' to add to podFile:

target 'OneSignalNotificationServiceExtension' do
  pod 'OneSignalXCFramework', '>= 5.0', '< 6.0'
  use_frameworks! :linkage => podfile_properties['ios.useFrameworks'].to_sym if podfile_properties['ios.useFrameworks']
end`;

I can see it installs:

[INSTALL_PODS] Installing react-native-onesignal (5.0.0)
[INSTALL_PODS] Installing OneSignalXCFramework (5.0.1)

But when fastlane is run I get the dreaded:

(ios/OneSignalNotificationServiceExtension/NotificationService.m:1:9)

> 1 | #import <OneSignal/OneSignal.h>
    |         ^ 'OneSignal/OneSignal.h' file not found

Any idea?

for this issue, I've used patch-package to not only update the iosContants but also the support/serviceExtensionFiles/NotificationService.m and replace

#import <OneSignal/OneSignal.h>

with

#import <OneSignalFramework/OneSignalFramework.h>

since react-native-onesignal uses OneSignalFramework header now instead of OneSignal, works for me @killerchip

Diaa-Ghonim commented 11 months ago

same issue here.

I spent all of the day to resolve it but nothing worked.

'OneSignal.h' file not found

killerchip commented 11 months ago

same issue here.

I spent all of the day to resolve it but nothing worked.

'OneSignal.h' file not found

@Diaa-Ghonim See @aindong response https://github.com/OneSignal/react-native-onesignal/issues/1440#issuecomment-1710521746

Diaa-Ghonim commented 11 months ago

same issue here. I spent all of the day to resolve it but nothing worked. 'OneSignal.h' file not found

@Diaa-Ghonim See @aindong response #1440 (comment)

it is not a completed answer, which parts I have to patch them. and I am not using expo I am using react-native and I use react-native-onesignal 4.4.1

and I added this to my pod file

target 'OneSignalNotificationServiceExtension' do pod 'OneSignalXCFramework', '>= 3.0', '< 4.0' end

anyone can explain clear steps please to fix this issue??

my machine is mac m1 my xcode is 14.3

killerchip commented 11 months ago

1.3.2 [Bug]: 'onesignal/onesignal.h' file not found react native OneSignal/onesignal-expo-plugin#182

it should be pod 'OneSignalXCFramework', '>= 5.0', '< 6.0' (see versions)

Also check if you have a NotificationService.m file. Replace #import <OneSignal/OneSignal.h> with #import <OneSignalFramework/OneSignalFramework.h>

Diaa-Ghonim commented 11 months ago

1.3.2 [Bug]: 'onesignal/onesignal.h' file not found react native OneSignal/onesignal-expo-plugin#182

it should be pod 'OneSignalXCFramework', '>= 5.0', '< 6.0' (see versions)

Also check if you have a NotificationService.m file. Replace #import <OneSignal/OneSignal.h> with #import <OneSignalFramework/OneSignalFramework.h> I apologize for any confusion. Here's a corrected version in English:

Unfortunately, the issue remains unresolved. I upgraded the react-native-onesignal library to the latest version and updated the Podfile from version 5 to 6. However, I'm still encountering this error:

'OneSignalFramework/OneSignalFramework.h' file not found

I am using react-native version "0.63.3".

arnaudambro commented 11 months ago

https://documentation.onesignal.com/docs/ios-sdk-setup#4-notification-service-extension

maybe in the objective-c file, write OneSignalExtension where you have OneSignal or OneSignalFramework ?

#import <OneSignalExtension/OneSignalExtension.h>

instead of

#import <OneSignal/OneSignal.h> // or #import <OneSignalFramework/OneSignalFramework.h>

not sure about it though, but at home it seems to compile

Diaa-Ghonim commented 11 months ago

Here is the issue in this file in node_modules.

Screenshot 2023-09-12 at 3 18 14 PM
Diaa-Ghonim commented 11 months ago

any idea?

arnaudambro commented 11 months ago

I confirm on my side: for OneSignal v5+, I replace #import < OneSignalFramework/OneSignalFramework .h> or #import <OneSignal/OneSignal.h> with

#import <OneSignalExtension/OneSignalExtension.h>

and it's compiling

Diaa-Ghonim commented 11 months ago

Hello @arnaudambro,

Thank you for your reply.

Where exactly should I add this line?

Here is my react-native-onesignal package in node_modules (version 4.4.1) (first image).

And here, as well, is the pods file and the react-native-onesignal pod (second image).

So, what should I do exactly to make the compilation succeed?

Screenshot 2023-09-14 at 2 36 44 PM Screenshot 2023-09-14 at 2 38 45 PM
arnaudambro commented 11 months ago

you should have a Notification Service Extension: https://documentation.onesignal.com/docs/ios-sdk-setup#4-notification-service-extension

quoting:

The OneSignalNotificationServiceExtension allows your iOS application to receive rich notifications with images, buttons, and badges. It's also required for OneSignal's Confirmed Delivery analytics features. In Xcode Select File > New > Target... Select Notification Service Extension then press Next. Enter the product name as OneSignalNotificationServiceExtension and press Finish. Do not select Activate on the dialog that is shown after selecting Finish. Press Cancel on the Activate scheme prompt. By canceling, you are keeping Xcode debugging your app, instead of the extension you just created. If you activated by accident, you can switch back to debug your app within Xcode (next to the play button). In the project navigator, select the top-level project directory and select the OneSignalNotificationServiceExtension target in the project and targets list. Ensure the Deployment Target is set to the same value as your Main Application Target. Unless you have a specific reason not to, you should set the Deployment Target to be iOS 11 or above. In the project navigator, click the OneSignalNotificationServiceExtension folder and open the NotificationService.m or NotificationService.swift and replace the whole file's contents with the following code. Ignore any build errors at this point. We will import OneSignal which will resolve any errors.

#import <OneSignalExtension/OneSignalExtension.h>

#import "NotificationService.h"

@interface NotificationService ()

@property (nonatomic, strong) void (^contentHandler)(UNNotificationContent *contentToDeliver);
@property (nonatomic, strong) UNNotificationRequest *receivedRequest;
@property (nonatomic, strong) UNMutableNotificationContent *bestAttemptContent;
...

this is where the OneSignal/OneSignal.h file not found comes from, because it used to be #import <OneSignal/OneSignal.h>, now it's #import <OneSignalExtension/OneSignalExtension.h>

aindong commented 11 months ago

For expo users, new update on the expo plugin is out, it should fix your problems about the missing header https://github.com/OneSignal/onesignal-expo-plugin/releases/tag/2.0.0

nachoviejo commented 11 months ago

I have a Mac M1, react native 0.68.5 and OneSignal 4.5.0. For some reason cocoapods is not installing correctly pods so, after weeks dealing with this issue, I've fixed it doing the following steps:

  1. Update cocoapods and ffi to last version.
  2. Delete from podfile everything related with OneSignal. And add this:
    post_install do |installer|
       react_native_post_install(installer)
       __apply_Xcode_12_5_M1_post_install_workaround(installer)
    end
  3. On Xcode, open xcworkspace, go to OneSignalNotificationServiceExtension target > General > Frameworks and Libraries and add:
Screenshot 2023-09-15 at 11 01 20

I have only those, if you have another one that can cause and error you need to remove it.

  1. Do a full clean and run it again:
rm -rf node_modules && yarn install
cd ios && pod deintegrate
rm -rf podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod install
npx react-native run ios (or the command that you use to run it)

I hope this helps!

matheusroomao commented 10 months ago

olá consegui resolver alterando #import <OneSignalFramework/OneSignalFramework.h> para #import <OneSignal/OneSignal.h> Versão: OneSignal 4.5.1, React-native 0.72.4, Xcode 15.0, macOS ventura 13.5.2,

Diaa-Ghonim commented 10 months ago

I tried all these solutions but didn't fix the issue.

any help please?

sn-will commented 10 months ago

I have a Mac M1, react native 0.68.5 and OneSignal 4.5.0. For some reason cocoapods is not installing correctly pods so, after weeks dealing with this issue, I've fixed it doing the following steps:

  1. Update cocoapods and ffi to last version.
  2. Delete from podfile everything related with OneSignal. And add this:
post_install do |installer|
     react_native_post_install(installer)
     __apply_Xcode_12_5_M1_post_install_workaround(installer)
end
  1. On Xcode, open xcworkspace, go to OneSignalNotificationServiceExtension target > General > Frameworks and Libraries and add:
Screenshot 2023-09-15 at 11 01 20

I have only those, if you have another one that can cause and error you need to remove it.

  1. Do a full clean and run it again:
rm -rf node_modules && yarn install
cd ios && pod deintegrate
rm -rf podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod install
npx react-native run ios (or the command that you use to run it)

I hope this helps!

Adding the .xcframework files into the Frameworks and Libraries of OneSignalNotificationServiceExtension worked for me

Diaa-Ghonim commented 10 months ago

I have a Mac M1, react native 0.68.5 and OneSignal 4.5.0. For some reason cocoapods is not installing correctly pods so, after weeks dealing with this issue, I've fixed it doing the following steps:

  1. Update cocoapods and ffi to last version.
  2. Delete from podfile everything related with OneSignal. And add this:
post_install do |installer|
     react_native_post_install(installer)
     __apply_Xcode_12_5_M1_post_install_workaround(installer)
end
  1. On Xcode, open xcworkspace, go to OneSignalNotificationServiceExtension target > General > Frameworks and Libraries and add:
Screenshot 2023-09-15 at 11 01 20

I have only those, if you have another one that can cause and error you need to remove it.

  1. Do a full clean and run it again:
rm -rf node_modules && yarn install
cd ios && pod deintegrate
rm -rf podfile.lock
rm -rf ~/Library/Developer/Xcode/DerivedData/*
pod install
npx react-native run ios (or the command that you use to run it)

I hope this helps!

Adding the .xcframework files into the Frameworks and Libraries of OneSignalNotificationServiceExtension worked for me

finally worked with me too

Thanks a lot ❤️ 🤙 ❤️

@nachoviejo @sn-will

hungMta commented 10 months ago

After adding OneSignal.xcframework ,.... I got another error:

Library not found for -lPods-OneSignalNotificationServiceExtension

Screenshot 2023-10-13 at 10 38 21

My environment: react-native: 0.63 xcode 14.2 macbook: M2-pro

TiagoAndreAlmeida commented 10 months ago

Tried every sugestion here but none work.... Xcode Version 15.0 react-native: 0.72.6 macbook: intel

Diaa-Ghonim commented 10 months ago

Unfortunately, this issue has occurred again, and I attempted the same solution, but it did not work.

help again guys 😢 😞

jmonloop commented 9 months ago

I got rid of this error by 1 pod deintegrate 2 pod update 3 Remove arm64 from excluded architecture at project and targets level

It's curious that I had to exclude the architecture and build to solve this problem

Then the import error appeared so I though by removing the excluded arch the linking error would show again but it didn't.

KennyLibaro commented 8 months ago

I'm not an expert on the topic but I think deintegrating and updating doesn't affect all files for some reason, I noticed the "OneSignal/OneSignal.h file not found" error I had was in the Development Pods folder I manually deleted everything in this folder and ran pod update again. this seemed to have resolved the problem for me.

Akshjani commented 6 months ago

Hello i am getting this error while building ipa from unity

error : 'OneSignalNotifications/OneSignalNotifications.h' file not found

Screenshot 2024-02-21 at 2 19 32 PM

from past 2 days i am battling with this error please help guysss

codeagus11 commented 3 weeks ago

Same issue here!