LoginSignup
2
0

More than 3 years have passed since last update.

iOSにFirebaseをpodで追加したが、クラッシュしてしまう問題の解決

Last updated at Posted at 2020-09-13

概要

Fabricを利用したクラッシュレポートの送信が、2020年11月15日で使えなくなるようで、
新しいFirebaseへの置き換えを進めてました。

https://firebase.google.com/docs/crashlytics/get-started?hl=ja
スクリーンショット 2020-09-13 8.42.51.png

プロジェクトは 共有frameworkアプリ側 で利用する形で、両方とも firebase を利用しています。
今までは、それぞれのプロジェクトで pod の追加をしていて、特に問題なく動いていました。

use_frameworks!

target 'library' do

  pod 'Firebase/Core', `古いバージョン`
  pod 'Firebase/Firestore', `古いバージョン`
  pod 'Firebase/Storage', `古いバージョン`
  pod 'Firebase/Crashlytics', `古いバージョン`

  target 'app' do

    pod 'Firebase/Core', `古いバージョン`
    pod 'Firebase/Firestore', `古いバージョン`
    pod 'Firebase/Storage', `古いバージョン`
    pod 'Firebase/Crashlytics', `古いバージョン`

  end  

end

ただし、今回以下のように、バージョンを新しいものに変えたら、ビルドができなくなってしまいました。
今回は、この解決例に関する記事です。

use_frameworks!

target 'library' do

  pod 'Firebase/Core'
  pod 'Firebase/Firestore'
  pod 'Firebase/Storage'
  pod 'Firebase/Crashlytics'

  target 'app' do

    pod 'Firebase/Core'
    pod 'Firebase/Firestore'
    pod 'Firebase/Storage'
    pod 'Firebase/Crashlytics'

  end  

end

環境

Mac : Catalina(10.15.6)
Xcode : 11.6
pod : 1.8.4

プロジェクト概要

プロジェクト内に、 共有Framework があり、
アプリからそれを参照している。

共有フレームワーク及び、アプリで fireabse を利用している。

エラー内容

まずコンパイルの段階で以下のような警告が出ます。

objc[1813]: Class GULZeroingWeakContainer is implemented in both ~~ One of the two will be used. Which one is undefined.

そして、ビルド時、 FirebaseApp.configure() でクラッシュ。

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        FirebaseApp.configure() // ここでクラッシュ

        return true
    }

クラッシュ時のエラー内容はこんな感じ。

myApps[1813:91118] *** Terminating app due to uncaught exception 'com.firebase.installations', reason: 'The default FirebaseApp instance must be configured before the defaultFirebaseApp instance can be initialized. One way to ensure that is to call `[FIRApp configure];` (`FirebaseApp.configure()` in Swift) in the App Delegate's `application:didFinishLaunchingWithOptions:` (`application(_:didFinishLaunchingWithOptions:)` in Swift).'
*** First throw call stack:

libc++abi.dylib: terminating with uncaught exception of type NSException

解決方法

結果、試行錯誤の末これでうまく行ったという感じなので、
うまく説明はできないのですが、
use_frameworks!
をライブラリ側につけない必要がありました。
そして、ライブラリは全部ライブラリ側に設定し、
アプリ側は inherit! :search_paths で参照します。

target 'library' do

  pod 'Firebase/Core'
  pod 'Firebase/Firestore'
  pod 'Firebase/Storage'
  pod 'Firebase/Crashlytics'

  target 'app' do
    use_frameworks!
    inherit! :search_paths
  end  

end

参考サイト

CocoaPodsでFirebaseをmain target以外に入れることができない問題(解決済)

解決にはこちらの記事が非常に参考になりました。
構成が違うためか、記事内容ではそのまま行かなく、 use_frameworks! の付け方で
うまく行ったという感じです。

このあたり、プロジェクトの構成次第でやり方が変わってきそうですね。

Firebase Crashlytics SDK にアップグレードする

今回の問題にハマるきっかけとなった、 Crashlytics の更新記事です。
ちなみに日本語記事だと、 android にも iOS での設定方法が書かれていたり、
ちょと記事がおかしいみたいなので、英語で確認することをおすすめします。

github

以下に、サンプルプロジェクトをアップしています。
ただし、ビルドには以下二点、対応が必要です。

  • pod update の実行が必要
  • GoogleService-Info.plist の追加が必要

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0