Somewhat like Build iOS App having Google Sign with support for Mac, I have embedded the Google Sign in for iOS framework and bundle into an Xcode project, but I'm targeting only iOS. My need in this is to use the Swift Package Manager with Google Sign In for iOS.
I am creating this question to add my current solution to this and to see if others have a solution. And to try to encourage Google to support Swift Package Manager with Google Sign In for iOS :).
The Swift Package Manager, or SwiftPM, has been around since Swift 3.0. It was initially only available for server-side or command line Swift projects. Since the release of Swift 5 and Xcode 11, SwiftPM is compatible with the iOS, macOS and tvOS build systems for creating apps.
On your iPhone or iPad, open the Safari app. Go to www.google.com. Tap your profile image or Sign in. Follow the sign-in steps.
The reversed client ID is your client ID with the order of the dot-delimited fields reversed. For example: com.googleusercontent.apps.1234567890-abcdefg.
On the Sign in methodtab, enable the Googlesign-in method and click Save. 1. Import the required header files First, you must import the Firebase SDK and Google Sign-In SDK header files into your app. Swift import Firebase import GoogleSignIn Objective-C
Before you can begin integrating your iOS app with the Google Sign-In components, you must download the dependencies and configure your Xcode project. The steps on this page do just that. The next steps then describe how to integrate Google Sign-In features into your app. Install a current version of Xcode.
Enable Google Sign-In in the Firebase console: In the Firebase console, open the Authsection. On the Sign in methodtab, enable the Googlesign-in method and click Save. 1. Import the required header files First, you must import the Firebase SDK and Google Sign-In SDK header files into your app. Swift
To ensure the SDK installation is successful, open AppDelegate.swift and import the SDK. If your sample app is able to build and run without any errors, then you are good to proceed to the next section.
Since the 6.0 release of Google Sign-In Framework the Swift Package Manager is supported natively.
There is no need for a workaround anymore. Simply use their Github URL to add the framework to SPM:
git clone https://github.com/google/GoogleSignIn-iOS
To this end, I have created an XCFramework version of Google Sign. See https://github.com/SyncServerII/GSignIn.git. So far, that is enabling testing and development with Xcode iOS Simulator and on actual iOS Devices.
Once built, this is used in a Package.swift manifest like:
.binaryTarget(
// This was generated using https://github.com/SyncServerII/GSignIn.git
name: "GSignIn",
path: "Frameworks/GSignIn.xcframework"
),
(See also https://github.com/SyncServerII/iOSGoogle/blob/main/Package.swift for a complete example).
Issues so far:
I am apparently unable to access the bundle assets. I have had to create a new Google Sign In button. Not a big deal, but for completeness I'd like to have access to the Google button the Google Sign In framework provides.
This package depends on a specific version of Google Sign In. Updating it will require going into https://github.com/SyncServerII/GSignIn.git and manually updating it based on updates to Google's Sign In framework.
I have yet to deploy an app using this package to the app store so that's an unknown at this point.
-- Updates --
12/28/20 (Resolved-- see 1/1/21 update below): I should also note that I'm getting a warning for this library in my sharing extension:
ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos/GSignIn.framework/GSignIn
when I build with this framework in my target app, which has a sharing extension. I have not tried to upload this app to the app store yet, so don't know what will happen then.
12/29/20 (Resolved-- see 1/1/21 update below): I was building previously with my Google Sign In package dragged into my app from a local directory. I have just tried moving from not dragged in, but to just relying on it as a swift package in my app, referenced using its Github repo. And that breaks the build with various obscure linker errors like the following:
Showing All Messages
Ld /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos/Share\ Extension.appex/Share\ Extension normal (in target 'Share Extension' from project 'Neebla')
cd /Users/chris/Developer/Neebla
/Applications/Xcode-12.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -target arm64-apple-ios14.0 -isysroot /Applications/Xcode-12.3.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.3.sdk -L/Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos -F/Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos -filelist /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Neebla.build/Debug-iphoneos/Share\ Extension.build/Objects-normal/arm64/Share\ Extension.LinkFileList -Xlinker -rpath -Xlinker @executable_path/Frameworks -Xlinker -rpath -Xlinker @executable_path/../../Frameworks -dead_strip -Xlinker -object_path_lto -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Neebla.build/Debug-iphoneos/Share\ Extension.build/Objects-normal/arm64/Share\ Extension_lto.o -Xlinker -export_dynamic -Xlinker -no_deduplicate -fembed-bitcode-marker -fapplication-extension -fobjc-link-runtime -L/Applications/Xcode-12.3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/iphoneos -L/usr/lib/swift -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Neebla.build/Debug-iphoneos/Share\ Extension.build/Objects-normal/arm64/Share_Extension.swiftmodule -lc++ -framework Accelerate -e _NSExtensionMain -Xlinker -no_adhoc_codesign -Xlinker -dependency_info -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Neebla.build/Debug-iphoneos/Share\ Extension.build/Objects-normal/arm64/Share\ Extension_dependency_info.dat -o /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos/Share\ Extension.appex/Share\ Extension -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/iOSFacebook.build/Debug-iphoneos/iOSFacebook.build/Objects-normal/arm64/iOSFacebook.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/iOSSignIn.build/Debug-iphoneos/iOSSignIn.build/Objects-normal/arm64/iOSSignIn.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ServerShared.build/Debug-iphoneos/ServerShared.build/Objects-normal/arm64/ServerShared.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/PersistentValue.build/Debug-iphoneos/PersistentValue.build/Objects-normal/arm64/PersistentValue.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/SwiftyUserDefaults.build/Debug-iphoneos/SwiftyUserDefaults.build/Objects-normal/arm64/SwiftyUserDefaults.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/KeychainAccess.build/Debug-iphoneos/KeychainAccess.build/Objects-normal/arm64/KeychainAccess.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/iOSShared.build/Debug-iphoneos/iOSShared.build/Objects-normal/arm64/iOSShared.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/swift-log.build/Debug-iphoneos/Logging.build/Objects-normal/arm64/Logging.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/SQLite.swift.build/Debug-iphoneos/SQLite.build/Objects-normal/arm64/SQLite.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Facebook.build/Debug-iphoneos/FacebookLogin.build/Objects-normal/arm64/FacebookLogin.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Facebook.build/Debug-iphoneos/FacebookCore.build/Objects-normal/arm64/FacebookCore.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Facebook.build/Debug-iphoneos/FacebookShare.build/Objects-normal/arm64/FacebookShare.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/iOSDropbox.build/Debug-iphoneos/iOSDropbox.build/Objects-normal/arm64/iOSDropbox.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/SwiftyDropbox.build/Debug-iphoneos/SwiftyDropbox.build/Objects-normal/arm64/SwiftyDropbox.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Alamofire.build/Debug-iphoneos/Alamofire.build/Objects-normal/arm64/Alamofire.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ImageIOSwift.build/Debug-iphoneos/ImageIOUIKit.build/Objects-normal/arm64/ImageIOUIKit.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ImageIOSwift.build/Debug-iphoneos/ImageIOSwift.build/Objects-normal/arm64/ImageIOSwift.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/SMLinkPreview.build/Debug-iphoneos/SMLinkPreview.build/Objects-normal/arm64/SMLinkPreview.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/swift-log-file.build/Debug-iphoneos/FileLogging.build/Objects-normal/arm64/FileLogging.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/iOSBasics.build/Debug-iphoneos/iOSBasics.build/Objects-normal/arm64/iOSBasics.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/Version.build/Debug-iphoneos/Version.build/Objects-normal/arm64/Version.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ChangeResolvers.build/Debug-iphoneos/ChangeResolvers.build/Objects-normal/arm64/ChangeResolvers.swiftmodule -Xlinker -add_ast_path -Xlinker /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Intermediates.noindex/ServerAccount.build/Debug-iphoneos/ServerAccount.build/Objects-normal/arm64/ServerAccount.swiftmodule
ld: warning: linking against a dylib which is not safe for use in application extensions: /Users/chris/Library/Developer/Xcode/DerivedData/Neebla-aybzuiaoyytaypbvqtqeummvcssh/Build/Products/Debug-iphoneos/GSignIn.framework/GSignIn
Undefined symbols for architecture arm64:
"iOSGoogle.GoogleHashing.init() -> iOSGoogle.GoogleHashing", referenced from:
Share_Extension.ServerInterface.addHashingForCloudStorageSignIns(hashingManager: iOSShared.HashingManager) throws -> () in ServerInterface+CloudHashing.o
"type metadata for iOSGoogle.GoogleHashing", referenced from:
Share_Extension.ServerInterface.addHashingForCloudStorageSignIns(hashingManager: iOSShared.HashingManager) throws -> () in ServerInterface+CloudHashing.o
"protocol witness table for iOSGoogle.GoogleHashing : iOSShared.CloudStorageHashing in iOSGoogle", referenced from:
Share_Extension.ServerInterface.addHashingForCloudStorageSignIns(hashingManager: iOSShared.HashingManager) throws -> () in ServerInterface+CloudHashing.o
"type metadata accessor for iOSGoogle.GoogleSyncServerSignIn", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"iOSGoogle.GoogleSyncServerSignIn.__allocating_init(serverClientId: Swift.String, appClientId: Swift.String, signInDelegate: iOSGoogle.GoogleSignInDelegate) -> iOSGoogle.GoogleSyncServerSignIn", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"direct field offset for iOSGoogle.GoogleSyncServerSignIn.userType : ServerShared.UserType", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"protocol witness table for iOSGoogle.GoogleSyncServerSignIn : iOSSignIn.GenericSignIn in iOSGoogle", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"type metadata accessor for iOSApple.AppleSignIn", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"iOSApple.AppleSignIn.__allocating_init() -> iOSApple.AppleSignIn", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
"protocol descriptor for iOSGoogle.GoogleSignInDelegate", referenced from:
l_got.$s9iOSGoogle20GoogleSignInDelegateMp in Services+SignIns.o
"protocol witness table for iOSApple.AppleSignIn : iOSSignIn.GenericSignIn in iOSApple", referenced from:
Share_Extension.Services.getSignIns(configPlist: Share_Extension.ConfigPlist) -> [(iOSSignIn.GenericSignIn, iOSSignIn.SignInDescription)] in Services+SignIns.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Note that this is not specific to building for a real device (e.g., arm64
). If I build for the simulator, I get the same kind of messages, but the heading is Undefined symbols for architecture x86_64:
.
When I build and still include my Google Sign In package (with references in my main app), but have no references to this package in my sharing extension, it builds cleanly. I'm taking this as more evidence that this package cannot be used in a sharing extension.
1/1/21: I now have the both above linker issues resolved. The first was just a switch I needed to change in my https://github.com/SyncServerII/GSignIn.git Xcode project (see warning message linking against a dylib which is not safe for use in application extensions). The second was just that I hadn't added my framework reference (for iOSGoogle in my case) into my sharing extension. See, for example, https://stackoverflow.com/a/61848359/1675875
2/3/21: I ran into some other issues, with using XCFrameworks in a sharing extension when I uploaded my app to iTunes Connect:
https://developer.apple.com/forums/thread/662247
App Store Connect Operation Error ERROR ITMS-90680: "Invalid directory. The bundle Payload/Neebla.app/PlugIns/GSignIn.framework is not contained in a correctly named directory. It should be under "Frameworks"." See https://forums.swift.org/t/swift-package-binary-framework-issue/41922/2 and https://bugs.swift.org/browse/SR-13840
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With