1

I am trying to create a swift framework containing both facebook and google SDKs for login, so that by implementing my framework, both of them may be used in a project without embedding them separately. I found out I can use pods for facebook SDK, but I have to add google SDK manually into my framework.
To reach classes in google SDK, I tried to add

#import <GoogleSignIn/GoogleSignIn.h>

into framework's umbrella header. However, when embedding my framework into project, it states that the file cannot be found.

I tried using the module approach instead. I created module.modulemap file defining GoogleSignIn module. I had no problem using the module in a framework.
However, when embedding my framework in a project, it states that module cannot be found. I even tried to import Google SDK into project itself and creating module in a project, but the error did not disappeared.

Could you please help me how to import google SDK into framework so that I can use my own framework in a project without any problems? Thank you in advance.

  • My personal opinion is this is poor design. In order to include your framework in anything, you are (1) adding bloated code for something that may not be needed, (2) hiding this from other developers who thought they were simply importing your framework, and (3) are opening things up for duplicate definitions when someone wishes to import both your framework and either FaceBook of Google logins classes. Frameworks don't usually work this way - please consider the downstream ramifications of your design. –  Aug 24 '17 at 17:45
  • @dfd this is not the solution to the problem. I am facing the same issue when using zip library under my framework and when I ship my framework, zip module is not available to project. – Manish Nahar Jan 17 '19 at 13:10
  • @Manish_Nahar, Maybe that's why I only added my *opinoin* as a comment instead of an answer! (I still think this is bad design to include third party frameworks in your own framework - because you want to make thing easier somehow.) Maybe your current issue is different than this 1.5 year older issue? If so, please, post a question with your specifics (and let me know) and I'll try to help. Consider a Framework target to be exactly like an API... why are you thinking **any** dependency should be included? –  Jan 17 '19 at 16:09

1 Answers1

0

You can do this with an Objective-C bridging header.

First add an objective c file, then you will be prompted to create a bridging header. Click yes and then delete the other objective c file.

In this file place your import statement:

#import <GoogleSignIn/GoogleSignIn.h>

(This is assuming you have imported the SDK manually.)

Make sure you've imported your framework in Linked Frameworks and Libraries, embedded binaries and to Target Dependencies in the app's Build Phases setting. for this to work. In this solution, you can add the swift framework .xcodeproj file as a file of the main swift project.

Pranav Kasetti
  • 8,770
  • 2
  • 50
  • 71
  • Yes, this works, but problem is that I need to implement functions for google sign in in the framework and call them in my project. To create functions using Google sign in, I have to import it or create a module in my framework. My framework is built without any problems. Problem occurs when I embed my framework in the project, project finds error on line when header or module was imported in a framework. –  Aug 24 '17 at 16:50
  • Have you tried creating and using a bridging header with these Objective C imports in your framework? – Pranav Kasetti Aug 24 '17 at 17:00
  • Yes, it was the first thing I did. I imported the GoogleSignIn.h in umbrella header of my framework. It built without any problems. When I embedded the framework in project, it found error in framework ion line where I imported GoogleSignIn header. –  Aug 24 '17 at 17:10
  • Your file path may be the issue here. Also, have you tried the answer suggested here by Atul? https://stackoverflow.com/questions/33797212/import-objective-c-framework-into-swift-framework-project Also check if you have added the public keywords to your framework functions and necessary variables. – Pranav Kasetti Aug 24 '17 at 17:10
  • That does not solve my problem. He only tried to implement obj-C framework in a swift project. I am trying to implement swift project embedding swift framework embedding obj-C framework. Embedding obj-C framework in a swift framework does not make any problems. The problem occurs when I add swift framework into swift project. –  Aug 24 '17 at 17:23
  • ok i see. its probably a simple error. good to check if you have included the framework into embedded binaries and linked frameworks. But don't also import the google sign in frameworks in your swift project. This will cause errors. – Pranav Kasetti Aug 24 '17 at 17:28
  • My framework is in Embedded Binaries and in Linked frameworks of a project and GoogleSignIn framework is removed from project. It still shows the same error. –  Aug 24 '17 at 17:30
  • ok. have you added it as a target dependency in build phases of swift project? – Pranav Kasetti Aug 24 '17 at 17:31
  • When I click on add button of target dependencies it does not suggest my framework. –  Aug 24 '17 at 17:34
  • you needed to have added a sub .xcodeproj of your swift framework into your swift project for this to work – Pranav Kasetti Aug 24 '17 at 17:39
  • When I added .xcodeproj of my framework into project by creating reference, it did not suggest framework when adding new target dependency and still showed that there is no module named GoogleSignIn. When I added .xcodeproj by copying items if needed in the project, there was error that info.plist file could not be found. –  Aug 24 '17 at 17:49
  • Adding the .xcodeproj into framework by copying items if needed creates the same mistake. When I click on it to see the files inside, all of them are red. Even if I add new files to it, they are red as well (as if missing). It again states that it cannot find Info.plist file, even though I added it manually and copied items. –  Aug 24 '17 at 18:09
  • Best to move the .xcodeproj you imported to trash and try again but import the whole .xcodeproj with subdirectories and files. – Pranav Kasetti Aug 24 '17 at 18:23
  • You can then click on the folder icon in the file inspector if you still get red – Pranav Kasetti Aug 24 '17 at 18:24
  • I did exactly that, I imported the whole .xcodeproj with subdirectories and they were all red. –  Aug 24 '17 at 18:29
  • Ok. Don't worry! You have to click the folder icon on the right hand pane for your directories and xcodeproj and select the directory you copied to! :-) – Pranav Kasetti Aug 24 '17 at 18:32
  • I added it via finder and result is still the same. The Info.plist file is still missing. –  Aug 24 '17 at 18:39
  • Have you clicked on the folder icon for the red info.plist? – Pranav Kasetti Aug 24 '17 at 18:41
  • This should be fairly simple to debug – Pranav Kasetti Aug 24 '17 at 18:42
  • I tried to fix it following the answers here: https://stackoverflow.com/questions/9880184/could-not-read-from-info-plist but the result is still the same. –  Aug 24 '17 at 18:55
  • Read this: https://stackoverflow.com/questions/4613358/move-xcode-project-causes-red-textmissing-files-from-project. The second answer here from hard.core.coder is what you need – Pranav Kasetti Aug 24 '17 at 19:30
  • I cannot navigate to that. When I click on a folder icon, it open Finder in a folder where .xcodeproj is located. I cannot open it and navigate into Info.plist. –  Aug 24 '17 at 19:39
  • Well if you're clicking the folder icon for the plist then you need to navigate into info.plist. otherwise you navigate to containing directories or the framework xcodeproj depending on what file you've selected on the left hand side file inspector. – Pranav Kasetti Aug 24 '17 at 21:22
  • I'd like to navigate to Info.plist, however, it opens in a folder where .xcodeproj is situated and Finder treats it as a file, not a folder. Therefore I cannot open in, to navigate to Info.plist. –  Aug 24 '17 at 21:48
  • Have you copied the files into your swift project? – Pranav Kasetti Aug 25 '17 at 06:43
  • Yes, I did do that. –  Aug 25 '17 at 07:31
  • This may be because you dragged the framework project into the existing xcodeproj for your swift project. try adding it outside of the existing xcodeproj scope. – Pranav Kasetti Aug 25 '17 at 08:15