21

I've installed FBSDK with Cocoapods but can't import it in my AppDelegate.swift file for some reason. The FBSDK kit appears in my Xcode project so I feel like it should be working. enter image description here

I'm not an iOS developer by any means, I'm just trying to write a simple native plugin for Flutter SDK. Anyone an idea?

--Here is what the pod file looks like--

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

if ENV['FLUTTER_FRAMEWORK_DIR'] == nil
  abort('Please set FLUTTER_FRAMEWORK_DIR to the directory containing Flutter.framework')
end

target 'Runner' do
  use_frameworks!

  # Pods for Runner
pod 'FBSDKCoreKit'
pod 'FBSDKLoginKit'
pod 'FBSDKShareKit'

  # Flutter Pods
  pod 'Flutter', :path => ENV['FLUTTER_FRAMEWORK_DIR']

  if File.exists? '../.flutter-plugins'
    flutter_root = File.expand_path('..')
    File.foreach('../.flutter-plugins') { |line|
      plugin = line.split(pattern='=')
      if plugin.length == 2
        name = plugin[0].strip()
        path = plugin[1].strip()
        resolved_path = File.expand_path("#{path}/ios", flutter_root)
        pod name, :path => resolved_path
      else
        puts "Invalid plugin specification: #{line}"
      end
    }
  end
end

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

---EDIT---

I''m getting the following error atm: FBSDKCoreKit.framework: No such file or directory.When I open the Frameworks folder in xCode, all file names are in red: enter image description here But that exact folder in Finder is empty. So I guess that's why the error is showing. The question is how to fix this...

This is what my embedded binaries and linked frameworks and libraries look like in the project: enter image description here

8
  • Please check my answer from this thread stackoverflow.com/a/44787352/3632832
    – byJeevan
    Jun 28, 2017 at 17:22
  • add framework to embedded binaries.
    – KKRocks
    Jun 28, 2017 at 18:20
  • @KKRocks How would one do that? Jun 28, 2017 at 18:23
  • select project target and you can see there this option.
    – KKRocks
    Jun 28, 2017 at 18:25
  • @KKRocks I find this in my Pods project under "Build Phases" but can't seem to find it in my Runner project. Like I said, I'm just trying to make a plugin. The project was pre-created so might be a bit strange :/ Jun 28, 2017 at 18:31

11 Answers 11

33
+50
  1. Select your Project Target
  2. Go to Build Settings.
  3. Search for Header Search Paths.
  4. Add this value $(SRCROOT)/Pods with recursive, then Xcode will resolve the path for you.

enter image description here

5
  • 4
    In xcode v11 the following worked for me: $(SOURCE_ROOT)/Pods/** Feb 6, 2018 at 21:56
  • @BramVanbilsen Thanks a lot - you save my day. I wish I can award you bounty too. Mar 6, 2019 at 7:43
  • @bryan Thanks a lot. After a day long of headache, i found the solution. Super!!!
    – ADK
    Jun 25, 2019 at 17:32
  • 2
    I have done this still it's not working. Please help. Mar 19, 2021 at 8:53
  • I had to make it recursive for the Header search paths. Also added $(SRCROOT)/Pods to the Framework search paths and also made it recursive before it worked for me
    – nivla360
    Aug 31, 2023 at 15:13
13

Are you opening the .xcodeproj or the .xcworkspace? Make sure it is the workspace whenever you install a cocoapod

0
5

I'll naively suppose you don't have use_frameworks! in you Podfile. If that's true, than you have two ways to go from here:

  1. In your Runner-Bridging-Header.h add #import <FBSDKCoreKit/FBSDKCoreKit.h>, remove import FBSDKCoreKit from AppDelegate.swift and just continue writing the code.

  2. Add use_frameworks! to your Podfile and run pod install again. That might bring some other issues, but if that works, than I'd suggest it.

3
  • use_frameworks! is already in there. The other option gives me an error: /Users/bramvanbilsen/Desktop/facebook_sign_in/facebook_sign_in/example/ios/Pods/FBSDKCoreKit/FBSDKCoreKit/FBSDKCoreKit/Internal/AppEvents/FBSDKAppEvents+Internal.h:19:9: fatal error: 'FBSDKCoreKit/FBSDKAppEvents.h' file not found #import <FBSDKCoreKit/FBSDKAppEvents.h> Jun 28, 2017 at 18:25
  • Can you show your Podfile? This looks like some strange path you've sent, considering that your app is called Runner
    – S2dent
    Jun 28, 2017 at 20:44
  • I added it to my question! The app is actually a plugin for Flutter (framework for by google) to allow iOS users to login with Facebook. So the iOS project is auto generated, that's why it's weird... I got it to work on a fresh new project, but need it to work with this auto generated project as well. Jun 28, 2017 at 20:50
3

If you use cocoapods, it should have generated a *.xcworkspace file for you. Open this file instead so your project can see the FBSDK installed and has reference to it.

0
3

When you install your pods, you must build your application first. Then your imports stop showing errors.

2
  • 1
    Not sure why this didn't get more traction. I didn't realize this and running my app instantly allowed me to import the cocoa pods - thanks!
    – Carter4502
    Nov 19, 2019 at 15:58
  • This answer needs to be higher Aug 21, 2021 at 8:34
2

Why not simply use the Swift pods?-

pod 'FacebookCore'
pod 'FacebookLogin'
pod 'FacebookShare'

and then import as normal, like-

import FBSDKLoginKit
import FacebookLogin

Once done, do a clean and build (command/⌘ + Shift + K) and Build (command/⌘ + B). Make sure you are using the .xcworkspace file to open the project.

More info on Swift FBSDK here.

Once you use the Swift pods, you should see these Frameworks in your project.

enter image description here

If you still continue to see the error then "Clean the build folder" using command + shift + alt + K.

2
  • But the pods I used worked in a clean new swift project. So I don't see why they should not be working for this one... Jul 8, 2017 at 10:44
  • It's up to you what you want to use. Pods are installed per project and there could be many things that might have gone wrong with this project's pod install. Check the targets for the frameworks installed or just try to reinstall the pods (remove pod entry from pod file and run install and then add it again and install). Jul 8, 2017 at 10:54
0

Start by cleaning your project using Command + Shift + K then close the project and delete the pods folder and the pod.lock file and your .xcworkspace file. Then run pod install and see if that fixes the issue.

1
  • I tried that and after building the project I get the following kind of error for every dependency installed with cocoa pods: error: /Users/bramv/Documents/Flutter-Facebook-Sign-In-Plugin/example/ios/build/Debug-iphoneos/FBSDKCoreKit/FBSDKCoreKit.framework: No such file or directory Jun 29, 2017 at 10:09
0

First Clean your project directory. And add $(inherited) in framework search path in Build settings.

4
  • Then add your framework path to your Framework search path. Like Target -> Build Settings -> Framework Search Paths -> "your Local Directory path like "/Users/user/Documents/FacebookSDKs" Jul 3, 2017 at 11:18
  • What should this local path directory be? I didn't manually download the sdk like in the old days. That why I am trying to use pods :) Jul 3, 2017 at 11:52
  • should $(inherited) be recursive or non-recursive? Jan 23, 2019 at 13:25
  • It's non-recursive Jan 28, 2019 at 6:47
0

As importing the FBSDKCoreKit.framework etc. will be performed in the [CP] Embed Pods Frameworks build phase when using CocoaPods, you should remove the references to these frameworks in the Embed Frameworks build phase.

CocoaPods will not create those references, I assume you have tried other ways of importing the Facebooks frameworks, and these link have been created in the process. You can also delete the references to the Facebook frameworks in the Frameworks Folder of you App-Project (the ones in your screenshot written in red, not the ones in the Pods-Project!), but keep the Pods_Runner.framework there.

From what I can tell, your Linked Frameworks and Libraries section looks valid.

If it still doesn't work, I'd advise you to create a new Xcode Project with an empty Podfile, and only include the Facebook frameworks via CocoaPods. Importing the Facebook-SDK in the AppDelegate should work then, otherwise I can share a sample project with you. Then you should check your build setting and build phases, maybe something is wrong there. If you still can't figure out the problem, you will probably need to re-create you xcode-project and import all your files again.

Without a sample Project that reproduces the error, that's the best advise I can give.

Good Luck! :)

0

The above solutions for Header Search Path should work. If you are too lazy to go there. Copy podfile content, remove all pods, pod install, then revert your podfile, pod install again.... Should work ;-)

0

In my case, it was correctly installed but I realized the pod is Objective-C and couldn't import it on a Swift file. I had to create a bridging header to make it work.

Refer to this stackoverflow thread How to import existing Objective C classes in Swift

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.