akaffenberger / firebase-ios-sdk-xcframeworks

A small mirror for https://github.com/firebase/firebase-ios-sdk, to add support for binary (xcframework) distribution with swift package manager.
MIT License
134 stars 32 forks source link

Google Sign In button doesn't render correctly #35

Closed ionothanus closed 2 years ago

ionothanus commented 2 years ago

Hi - hoping someone might have some ideas on how to address this issue.

I had previously wrapped the UIKit Google Sign In button in my SwiftUI app. When I was using the standard (not pre-compiled) Firebase packages, this rendered well. Now that I've switched to these pre-compiled packages, the button does not render any images or text: Broken Google Sign In Button

I tried to switch to the now-existing SwiftUI implementation in the Google library, but import GoogleSignInSwift doesn't seem to exist in these pre-compiled packages, I can't find it in the list of frameworks/libraries to add. I would separately import the GoogleSignIn-iOS package, but it offers a library/framework/etc. of the same name GoogleSignIn as what's provided in this repo, so Xcode won't let me use both Swift packages at the same time.

Whose issue is this: the pre-compiled Firebase package (for not providing the GoogleSignInSwift module and/or breaking the UIKit button implementation somewhere between the last version I was using and 9.1.0), this Swift package wrapping them (for interfering with exposing the Swift module and/or the rendering of the UIKit button), or mine (for... misconfiguring something I guess)? How can I start to tease that out? And is there a way to work around this where I can import the separate GoogleSignIn-iOS package?

In case it matters, here's the UIKit wrapper that's broken:

import SwiftUI
import GoogleSignIn

struct GoogleSignInButton: View {
    @Environment(\.colorScheme) var colorScheme

    var body: some View {
        Group {
            if colorScheme == .light { // (2)
                GoogleSignInButtonInternal(colorScheme: .light)
            }
             else {
                GoogleSignInButtonInternal(colorScheme: .dark)
            }
        }
    }
}

fileprivate struct GoogleSignInButtonInternal: UIViewRepresentable {
    var colorScheme: ColorScheme

    func makeUIView(context: Context) -> GIDSignInButton {
        let button = GIDSignInButton()
        switch colorScheme {
            case .dark:
                button.colorScheme = .dark
                return button
            case .light:
                button.colorScheme = .light
                return button
            @unknown default:
                fatalError()
        }
    }

    func updateUIView(_ uiView: UIViewType, context: Context) {
    }
}

Any ideas would be greatly appreciated!

ionothanus commented 2 years ago

After taking a quick peek (while knowing nothing about any of this) I'm guessing the Firebase-provided xcframework for GoogleSignIn doesn't provide/expose the GoogleSignInSwift module, for some reason. And possibly may be incorrectly building the GoogleSignIn xcframework in a way that it does not load the images/fonts/strings correctly. Any ideas on how I might confirm, so I can open an issue in the firebase-ios-sdk repo where that xcframework is sourced?

In the meantime, I forked the repo, copied the resources & source code for GoogleSignInSwift into it (hacking around until I got the resources & bundle names right), and added that to the Package.swift definition. That seems to have resolved my rendering issue for now.

akaffenberger commented 2 years ago

Hey @ionothanus, I tested your sample code and it seems to work ok:

I would double check that the resource bundle is properly linked to your project, you can find instructions for that in the readme, it's the last step for installation: https://github.com/akaffenberger/firebase-ios-sdk-xcframeworks#installation

To answer your question:

I'm guessing the Firebase-provided xcframework for GoogleSignIn doesn't provide/expose the GoogleSignInSwift module, for some reason. And possibly may be incorrectly building the GoogleSignIn xcframework in a way that it does not load the images/fonts/strings correctly. Any ideas on how I might confirm, so I can open an issue in the firebase-ios-sdk repo where that xcframework is sourced?

You could confirm this by removing the firebase-ios-sdk-xcframeworks package from your project and then follow Firebase's manual integration instructions: https://firebase.google.com/docs/ios/installation-methods#integrate-manually. If you still see issues with manual integration, then the issue is with the framework.

ionothanus commented 2 years ago

Noted: following all of the instructions is important 😄 My mistake, I'd actually skipped most of those instructions because the very first step didn't apply to me - I don't have a Package.swift to add this dependency to, to my knowledge, so I added the package reference through the project settings UI - and so I got confused about what those instructions were for.

I attempted to add the script provided in .scripts as a Run Script build phase. Unfortunately, it seemed to have no effect - I confirmed Xcode was attempting to run the script, but it produced no other output in the build log, and did not resolve the problem. I'm not sure how to debug that further.

Fortunately, dragging the resources directly into the "Copy Bundle Resources" step seems to have resolved the issue with the button rendering.

I took a look at the manual Firebase integration steps - there's no GoogleSignInSwift xcframework to be found there, so I'm going to guess it's not provided. I'll look into opening a ticket with the relevant project.

Thanks for your help!

akaffenberger commented 2 years ago

Thanks @ionothanus, glad it's working. I'll take a look at the resources script to see if I can repro the issue you're seeing.

akaffenberger commented 2 years ago

@ionothanus I see that GoogleSignInSwift was added in 9.2.0, nice! https://github.com/firebase/firebase-ios-sdk/issues/9900