OneSignal / OneSignal-Flutter-SDK

OneSignal is a free push notification service for mobile apps. This plugin makes it easy to integrate your flutter app with OneSignal
https://www.onesignal.com
Other
615 stars 213 forks source link

'Flutter/Flutter.h' file not found #550

Open shravanispr opened 2 years ago

shravanispr commented 2 years ago

Description:

After adding extension to the target, the app fails to build for iOS: Please refer the following for further info

Environment:

OneSignal Flutter package: onesignal_flutter: ^3.3.0 Followed all the instruction on the official documents from https://documentation.onesignal.com/docs/flutter-sdk-setup

Flutter doctor: Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.10.5, on macOS 11.4 20F71 darwin-arm, locale en-IN) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] IntelliJ IDEA Community Edition (version 2021.2.3) [✓] Connected device (3 available) [✓] HTTP Host Availability

Steps to Reproduce Issue:

  1. Create Flutter app with swift as IOS language
  2. Add onesignal_flutter: ^3.3.0 under dependencies
  3. Add OneSignalNotificationServiceExtension to the target as per the instruction in the official docs (https://documentation.onesignal.com/docs/flutter-sdk-setup) using swift language

Anything else: StackTrace:

Error output from Xcode build: ↳ objc[69926]: Class AMSupportURLConnectionDelegate is implemented in both /usr/lib/libauthinstall.dylib (0x1ebc86c10) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1113b82c8). One of the two will be used. Which one is undefined. objc[69926]: Class AMSupportURLSession is implemented in both /usr/lib/libauthinstall.dylib (0x1ebc86c60) and /System/Library/PrivateFrameworks/MobileDevice.framework/Versions/A/MobileDevice (0x1113b8318). One of the two will be used. Which one is undefined. BUILD FAILED

Xcode's output: ↳ Writing result bundle at path: /var/folders/d_/98vjmcy97zg200_p4pnc23vc0000gp/T/flutter_tools.Xw92Qm/flutter_ios_build_temp_dir1GAg9O/temporaryxcresult bundle

/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h:1:9: note: in file included from
/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h:1:
#import "GeneratedPluginRegistrant.h"
        ^
/Users/user/projects/project/ios/Runner/GeneratedPluginRegistrant.h:10:9: error: 'Flutter/Flutter.h' file not found
#import <Flutter/Flutter.h>
        ^
1 error generated.
<unknown>:0: error: failed to emit precompiled header
'/Users/user/Library/Developer/Xcode/DerivedData/Runner-gmxxqkynucxntvehaxszindrslcz/Build/Intermediates.noindex/Precom
piledHeaders/Runner-Bridging-Header-swift_DK39NET1WVNZ-clang_1MJTBDEFV075D.pch' for bridging header
'/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h'
/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h:1:9: note: in file included from
/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h:1:
#import "GeneratedPluginRegistrant.h"
        ^
2 errors generated.
remark: Incremental compilation has been disabled: it is not compatible with whole module optimization
error: generate-pch command failed with exit code 1 (use -v to see invocation)
note: Using new build system
note: Planning
note: Build preparation complete
note: Building targets in dependency order
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'leveldb-library' from
project 'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'sqlite3' from project
'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target
'flutter_downloader-FlutterDownloaderDatabase' from project 'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'FMDB' from project
'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'SAMKeychain' from
project 'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'OrderedSet' from
project 'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'MTBBarcodeScanner' from
project 'Pods')
/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'OneSignalXCFramework'
from project 'Pods')

Result bundle written to path:
    /var/folders/d_/98vjmcy97zg200_p4pnc23vc0000gp/T/flutter_tools.Xw92Qm/flutter_ios_build_temp_dir1GAg9O/temporary_xcresult_
    bundle

Error (Xcode): 'Flutter/Flutter.h' file not found /Users/user/projects/project/ios/Runner/GeneratedPluginRegistrant.h:9:8

Error (Xcode): failed to emit precompiled header '/Users/user/Library/Developer/Xcode/DerivedData/Runner-gmxxqkynucxntvehaxszindrslcz/Build/Intermediates.noindex/Precompile dHeaders/Runner-Bridging-Header-swift_DK39NET1WVNZ-clang_1MJTBDEFV075D.pch' for bridging header '/Users/user/projects/project/ios/Runner/Runner-Bridging-Header.h'

Encountered error while building for device.

jkasten2 commented 2 years ago

@shravanispr Thanks for reporting, the following like it could be root of your issue.

/Users/user/projects/project/ios/Pods/Pods.xcodeproj: warning: The iOS deployment target 'IPHONEOS_DEPLOYMENT_TARGET'
is set to 8.0, but the range of supported deployment target versions is 9.0 to 15.2.99. (in target 'leveldb-library' from
project 'Pods')

Could you check the top of your Podfile to make sure you have the following:

# Uncomment this line to define a global platform for your project
platform :ios, '9.0'

For extra context, this is step 3.8 in the OneSignal Flutter setup guide.

If above does not help could you let us know the following:

  1. Does this happen with a new Flutter project?
  2. Do you have any other plugins / SDK in your project? If so please list them and your versions.
  3. Please include the full contains of your Podfile.
shravanispr commented 2 years ago

@jkasten2 Global Platform for the project is higher than '9.0'

Yes, it is happening with the new project

Steps to Reproduce

  1. Create a new flutter project with swift as IOS language
  2. Add onesignal_flutter: ^3.3.0 under dependencies
  3. Add OneSignalNotificationServiceExtension to the target as per the instruction in the official docs (https://documentation.onesignal.com/docs/flutter-sdk-setup) using swift language

For new project I'm getting similar issues with additional error Framework not found Pods_Runner Other plugins and SDKs

dependencies:
  flutter:
    sdk: flutter
  flutter_localizations:
    sdk: flutter

  cupertino_icons: ^1.0.4
  http: ^0.13.4
  built_value: ^8.2.3
  built_collection: ^5.1.1
  intl: ^0.17.0
  rxdart: ^0.27.3

  firebase_core: ^1.15.0
  cloud_firestore: ^3.1.13
  firebase_analytics: ^9.1.6
  firebase_auth: ^3.3.16
  firebase_storage: ^10.2.14

  provider: ^6.0.2
  path_provider: ^2.0.9
  state_notifier: ^0.7.2+1
  flutter_state_notifier: ^0.7.1
  logger: ^1.1.0
  collection: ^1.15.0
  beamer: ^1.4.1+1
  hive: ^2.0.6
  hive_flutter: ^1.1.0
  hive_generator: ^1.1.2
  qr_flutter: ^4.0.0
  gallery_saver: ^2.3.2
  mailto: ^2.0.0
  url_launcher: ^6.0.20
  image_gallery_saver: ^1.7.1
  flutter_downloader: ^1.7.3
  in_app_review: ^2.0.4
  flutter_neumorphic: ^3.2.0
  lottie: ^1.3.0
  flutter_inappwebview: ^5.3.2
  onesignal_flutter: ^3.3.0

  image_picker: ^0.8.4+10
  flutter_image_compress: ^1.1.0
  file_picker: ^4.5.0
  permission_handler: ^9.2.0
  video_player: ^2.3.0
  flutter_svg: ^1.0.3
  cached_network_image: ^3.2.0
  youtube_player_flutter: ^8.0.0
  open_file: ^3.2.1
  image_crop: ^0.4.0
  vimeo_player_flutter: ^0.0.3+2
  webview_flutter: ^3.0.1
  qr_code_scanner: ^0.7.0
  dotted_border: ^2.0.0+2
  flutter_datetime_picker: ^1.5.1
  firebase_database: ^9.0.8
  flutter_udid: ^2.0.0
  flutter_chat_bubble: ^2.0.0
  drift: ^1.0.1
  sqlite3_flutter_libs:

Podfile

 #Uncomment this line to define a global platform for your project
platform :ios, '12.0'

#CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
  'Debug' => :debug,
  'Profile' => :release,
  'Release' => :release,
}

def flutter_root
  generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
  unless File.exist?(generated_xcode_build_settings_path)
    raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
  end

  File.foreach(generated_xcode_build_settings_path) do |line|
    matches = line.match(/FLUTTER_ROOT\=(.*)/)
    return matches[1].strip if matches
  end
  raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
  use_frameworks!
  use_modular_headers!

  flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    flutter_additional_ios_build_settings(target)
  end
end

target 'OneSignalNotificationServiceExtension' do
  use_frameworks!
  pod 'OneSignalXCFramework', '>= 3.4.3', '< 4.0'
end 
emawby commented 2 years ago

@shravanispr Is this still happening? I believe there was an issue with one of the iOS native podspecs that allowed the version to be lower than 9, but that has been fixed.

ynmain commented 2 years ago

This problem is still occurring. Happened with version 3.4.0, not with 3.3.2. It's a problem that needs to be resolved quickly.

Jeonguk-ninehire commented 1 year ago

I solved this problem by adding Run script in Extension target build phase.
Copied from Runner target build phase and put it on same sequence. /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

DenerOliveira1 commented 1 year ago

I solved this problem by adding Run script in Extension target build phase. Copied from Runner target build phase and put it on same sequence. /bin/sh "$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh" build

Thank you so much!

jonaheapen98 commented 8 months ago

Still facing this issue with the above fix. Has anyone resolved this? OneSignal version - 5.0.4

emawby commented 7 months ago

@jonaheapen98 This issue is a symptom of Cocoapods installation going wrong. Were you able to solve it?

joaoarmando commented 7 months ago

Any updates? I'm facing the same issue...

lakshydeep-14 commented 7 months ago

There is no issue while implementing in Android. Facing issue while implementing in iOS. Followed the official docs. Did all but stuck on this 👇 #import <Flutter/Flutter.h> not found Any solution?

ShvetsovZE commented 7 months ago

Same here, following the official documentation. Tried multiple times and every time ending up with

Error (Xcode): 'Flutter/Flutter.h' file not found

Looks like a common issue, @jkasten2 if there is any plan for the OneSignal team to fix or it's not a priority? Flutter package -> onesignal_flutter: ^5.0.4

ShvetsovZE commented 7 months ago

I just updated the package to 5.1.0 and the issue is still present. @Jeonguk-ninehire Could you send a screenshot of your solution please, as when i try to follow it, the build fails bout not being able to find a directory

Jeonguk-ninehire commented 7 months ago

@ShvetsovZE Here's my extension build phase run script and my OneSignal package version is 5.0.4 now. I wish it could help you. 스크린샷 2024-02-19 오전 9 58 57

ShvetsovZE commented 7 months ago

hey @Jeonguk-ninehire , thanks for coming back to me. It fixes the original issue, but another pops up now.

`Could not build the precompiled application for the device. Error (Xcode): Cycle inside Runner; building could produce unreliable results. Cycle details: → Target 'Runner': CodeSign /Users/user/Documents/development/repos/finelly-app/src/finelly/build/ios/Debug-qa-iphoneos/Runner.app ○ That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks” ○ That command depends on command in Target 'Runner': script phase “Thin Binary” ○ Target 'Runner' has process command with output '/Users/user/Documents/development/repos/finelly-app/src/finelly/build/ios/Debug-qa-iphoneos/Runner.app/Info.plist' ○ Target 'Runner' has copy command from '/Users/user/Documents/development/repos/finelly-app/src/finelly/build/ios/Debug-qa-iphoneos/OneSignalNotificationServiceExtension.appex' to '/Users/user/Documents/development/repos/finelly-app/src/finelly/build/ios/Debug-qa-iphoneos/Runner.app/PlugIns/OneSignalNotificationServiceExtension.appex' ○ That command depends on command in Target 'Runner': script phase “[CP] Copy Pods Resources”

I'm very new to flutter and ios, do you know what might caused it?

arwysyah commented 6 months ago

I solved the problem by copy Run Script in Build Phases from Runner to OneSignalNotificationServiceExtension Build Phases and then you will get an error Error (Xcode): Sandbox: rsync.samba(34407) deny(1) file-write-create... , you just need to set "User Script Sandboxing" in your "Build Settings" false onesignal_flutter: ^5.1.2 Xcode : 15.1

NOTE : if you get this error Could not build the precompiled application for the device. Error (Xcode): Cycle inside Runner; building could produce unreliable results. Cycle details: → Target 'Runner': CodeSign /Users/user/Documents/development/repos/finelly-app/src/finelly/build/ios/Debug-qa-iphoneos/Runner.app ○ That command depends on command in Target 'Runner': script phase “[CP] Embed Pods Frameworks”

move your Embedded Foundation Extension above your Run Script in Build Phases

hope it help