Help us understand the problem. What is going on with this article?

FirebaseをCocoaPodsでEmbeddedFrameworkなmain target以外にも入れたい

背景

以前、embedded frameworkを使ってFirebaseをmain target以外に入れることができたのだが

環境の更新でエラーとなってしまう事象が発生したので調査と対応

  • Xcode(10.3 -> 11.1)
  • Cocoapods(1.5.3 -> 1.8.4)
  • Firebase(4.13.0 -> 6.12.0)

事象

  • 環境情報
Xcode: 10.3 (11A1027)
CocoaPods: 1.5.3
Podfile
# Uncomment the next line to define a global platform for your project
platform :ios, '11.0'

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

target 'Domain' do

  target 'Infra' do
    inherit! :search_paths

    # Pods for Infra
    pod 'Alamofire'
    pod 'Firebase/Core', '~> 4.13.0'
    pod 'Firebase/Firestore'

    target 'EmbeddedFirebase' do
      inherit! :search_paths

      # Pods for EmbeddedFirebase
      pod 'Fabric'
      pod 'Crashlytics'

    end
  end
end

こんな感じの構成、Podfile(抜粋)です。Infra層でFirebaseを使いたかった

XcodeをUpdate

Xcode: 11.1 (11A1027)

-> ビルド:OK! 実行:OK!

CocoaPodsをUpdate

❯ bundle update

❯ bundle exec pod --version
1.8.4

-> ビルド:OK! 実行:NG!

dyld: Library not loaded: @rpath/Alamofire.framework/Alamofire
  Referenced from: ~/Library/Developer/CoreSimulator/Devices/C03D2C2B-D4C4-4251-A3DB-8D345B7C4A5A/data/Containers/Bundle/Application/FEA53091-4E07-4E1D-A16C-82EB3C0E1618/EmbeddedFirebase.app/EmbeddedFirebase
  Reason: image not found

Build Phasesから[CP] Embed Pods Frameworksが消えてる、、

とりあえずpod updateして見よう

❯ bundle exec pod update

-> 変わらず

Firebaseもupdateしてみる

Podfile
@@ -14,7 +14,7 @@ target 'Domain' do

     # Pods for Infra
     pod 'Alamofire'
-    pod 'Firebase/Core', '~> 4.13.0'
+    pod 'Firebase/Core'
     pod 'Firebase/Firestore'

     target 'EmbeddedFirebase' do

-> 変わらず

use_modular_headers! にすることで上記解決することができました

Podfileを修正

Podfile
@@ -2,7 +2,7 @@
 platform :ios, '11.0'

 # Comment the next line if you don't want to use dynamic frameworks
-use_frameworks!
+#use_frameworks!

 target 'Domain' do

-> ビルド:OK! 実行:OK!

なるほど解決、一件落着。と行きたいところだが結局の原因が不明?

解説: use_frameworks! とはなんなのか

Why do we use use_frameworks in CocoaPods?

use_frameworks tells CocoaPods that you want to use Frameworks instead of Static Libraries. Since Swift does not support Static Libraries you have to use frameworks.

つまり、'!use_frameworks'をつけると、CocoaPodsにstatic librariesの代わりにdynamic frameworkとして使いますと設定します

なぜ?
-> Xcode9.0、CocoaPods1.5.0未満の環境ではSwiftがStatic Librariesをサポートしていなかったらですね

現在の環境でしたらiOS10以降になっているはずなのでさっさと修正しましょう。

dylibsが増えると起動時間が長くなる問題もある

# before
Total pre-main time: 1.0 seconds (100.0%)
         dylib loading time: 668.83 milliseconds (63.5%)
        rebase/binding time:  14.29 milliseconds (1.3%)
            ObjC setup time:  30.45 milliseconds (2.8%)
           initializer time: 339.00 milliseconds (32.2%)
           slowest intializers :
             libSystem.B.dylib :   6.16 milliseconds (0.5%)
    libMainThreadChecker.dylib :  33.04 milliseconds (3.1%)
                         Infra : 270.55 milliseconds (25.7%)

# after
Total pre-main time: 598.13 milliseconds (100.0%)
         dylib loading time: 226.94 milliseconds (37.9%)
        rebase/binding time:   1.49 milliseconds (0.2%)
            ObjC setup time:  18.88 milliseconds (3.1%)
           initializer time: 350.80 milliseconds (58.6%)
           slowest intializers :
             libSystem.B.dylib :   5.98 milliseconds (1.0%)
    libMainThreadChecker.dylib :  34.12 milliseconds (5.7%)
                         Infra : 593.70 milliseconds (99.2%)

この数だと誤差かもなぁ

まとめ

動いているからといって放置せず、ツール・ライブラリはこまめにメンテナンスしろ!

でも、aws-sdk-iosだけは勘弁な

参考

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした