먹고 기도하고 코딩하라

[CocoaPods] GoogleSignIn 의존성 충돌 문제가 난다면... 본문

앱/Swift

[CocoaPods] GoogleSignIn 의존성 충돌 문제가 난다면...

사과먹는사람 2022. 7. 27. 14:18
728x90
728x90

 

1시간 정도 정말 많이 찾아보고 문서를 읽고 또 읽었지만 등잔 밑이 어둡다고 문제는 가까이에 있었다.

요약 : Podfile의 platform 주석을 해제하고, 현재 개발하는 프로젝트의 빌드 타겟에 맞는 버전을 적어주세요.

 

만들고 있는 앱에 파이어베이스를 붙여 구글로 로그인할 수 있도록 서비스를 만들고 있었다.

다음은 pod init 후 workspace를 열어 AppDelegate 파일을 수정한 코드이다.

import UIKit
import FirebaseCore
import GoogleSignIn

@main
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        FirebaseApp.configure()
        // Override point for customization after application launch.
        GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
        GIDSignIn.sharedInstance().delegate = self
        return true
    }
    
    func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
//        return GIDSignIn.sharedInstance().handle(url, sourceApplication: <#T##String?#>, annotation: <#T##Any?#>)
        return GIDSignIn.sharedInstance().handle(url)	// 이 부분이 에러가 남
    }

    // MARK: UISceneSession Lifecycle

    func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
        // Called when a new scene session is being created.
        // Use this method to select a configuration to create the new scene with.
        return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
    }

    func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
        // Called when the user discards a scene session.
        // If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
        // Use this method to release any resources that were specific to the discarded scenes, as they will not return.
    }
    
    func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
        
    }


}

두 번째 application 함수에서 GIDSignIn.sharedInstance().handle(url)을 하면 돼야 하는데 이게 안 되고 missing arguments for parameters 'sourceapplication', 'annotation' in call 하면서 에러가 났다. 그래서 억지로 sourceApplication, annotation 매개변수를 추가해줘야 했는데 이건 뭐 하려고 해도 할 수가 없는 상황.

도대체 어디서 잘못된 건지 이해할 수가 없어서 Podfile을 열었다.

 

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

target 'SocialLoginApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for SocialLoginApp
  pod 'FirebaseAuth'
  pod 'GoogleSignIn'

  target 'SocialLoginAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'SocialLoginAppUITests' do
    # Pods for testing
  end

end

FirebaseAuth와 GoogleSignIn을 넣고 pod install도 마쳐서 모든 의존성들이 다 설치된 상황이었다.

구글에 검색해 보니 5.0 이상부터 handle(url)만 쓸 수 있도록 되었다고 해서 아! 그럼 버전을 추가해주면 되겠구나 하고 수정했다.

  pod 'GoogleSignIn', '~> 5.0'

그리고 pod install 을 다시 실행했는데.. 이런 에러 메시지가 나왔다.

쉽게 말하자면, 현재 GTMSessionFetcher/Core 버전이 2.0.0인데.. 버전이 안 맞는다는 얘기였다.

도대체 이 버전을 어떻게 맞추는 건지 알 수 없어서 구글링을 여러 번 해봤지만 실패했다.

급기야 Podfile에 pod GTMSessionFetcher/Core 를 추가하는 기행까지 시도했지만 역시 통하지 않았다.

 

그런데... 혹시 아래 노랑색 경고 메시지가 보이시는지.

플랫폼이 설정되어 있지 않다는 메시지였다.

...혹시?? 하고 Podfile을 보니 맨 위에 이렇게 돼 있다.

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

platform이 주석 처리가 되어 있다. 

아니 그럼 설마 내가 지금 이것 때문에 헛수고를 하게 된 건가?? 싶어서 platform을 수정했다.

GoogleSignIn 팟 버전도 같이 올려서 수정했다.

# Uncomment the next line to define a global platform for your project
platform :ios, '15.5'

target 'SocialLoginApp' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!

  # Pods for SocialLoginApp
  pod 'FirebaseAuth'
  pod 'GoogleSignIn', '~> 6.0'

  target 'SocialLoginAppTests' do
    inherit! :search_paths
    # Pods for testing
  end

  target 'SocialLoginAppUITests' do
    # Pods for testing
  end

end

그러고 나서 다시 pod install --repo-update 시도.

이번에는 잘 동작한다...가 아니라 버전 6이 되면서 5와 많이 달라져서 마이그레이션이 번거롭다.

한 예시를 들자면 5에서 6으로 넘어가면서 GIDSignIn.sharedInstance()를 쓰려면 Cannot call value of non-function type 'GIDSignIn' 에러가 나면서 굉장히 성가시다.

문서가 있긴 하지만 부실해서 구체적인 디렉션을 알 수 없는 상황.

그런 고로 스택오버플로우에서 제일 많은 도움을 받을 수 있는 버전으로 다운그레이드를 하겠다.

  pod 'GoogleSignIn', '~> 5.0.2'

 

요약한다. platform 주석을 해제하고 버전을 써주는 것을 잊지 말자.

 

 

728x90
반응형
Comments