LoginSignup
16
7

More than 5 years have passed since last update.

XcodeGen + CocoaPods の組み合わせで Build Phases の一番最後に script を追加する

Posted at

TL; DR

Cocoapods の script_phase を使う


project.yml
name: ExampleApp
targets:
  ExampleApp:
    type: application
    platform: iOS
    sources: ExampleApp
    prebuildScripts:
      - name: Run SwiftLint
        script: ${PODS_ROOT}/SwiftLint/swiftlint
    postbuildScripts:
      - name: Run Fabric
        script: "${PODS_ROOT}/Fabric/run"

↑こんな project.yml だったときに

$ xcodegen
$ pod install

xcodegen -> pod install すると、postbuildScripts の後に Cocoapods の script が追加される。

Fabric の script は Cocoapods のものよりも後(一番最後)に呼ばないといけないので、困る。

なので、以下のように一番最後に追加したい script は Podfile に書く。

--- a/Podfile
+++ b/Podfile
@@ -7,4 +7,7 @@ target 'ExampleApp' do

   pod 'Fabric', '~> 1.7.2'
   pod 'Crashlytics', '~> 3.9.3'
+
+  script_phase :name => 'Run Fabric',
+               :script => '"${PODS_ROOT}/Fabric/run"'
 end

Podfile に移動した script は project.yml から消す。

--- a/project.yml
+++ b/project.yml
@@ -7,6 +7,3 @@ targets:
     prebuildScripts:
       - name: Run SwiftLint
         script: ${PODS_ROOT}/SwiftLint/swiftlint
-    postbuildScripts:
-      - name: Run Fabric
-        script: "${PODS_ROOT}/Fabric/run"

そうしてから xcodegen -> pod install すると、 Build Phases の最後に [CP-User] Run Fabric という名前の script が追加されて、めでたしめでたし。

16
7
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
16
7