🎉

「Command Phase~」と遭遇した時にPodfileに書くアレの正しい書き方

2023/06/15に公開

以下の参考記事

【Xcode】ビルド時に「Command PhaseScriptExecution failed with a nonzero exit code」エラーが発生する

https://cpoint-lab.co.jp/article/202203/22239/

上記を追加したら、次に Podfile に下記を追加します。

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      config.build_settings["EXCLUDED_ARCHS[sdk=iphonesimulator*]"] = "arm64"
    end
  end
end

を読んでいて疑問に思いました。

post_install do |installer|

target 'プロジェクト名' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  
  # Pods for VocaBuilNikki
  pod 'ライブラリ名'
  
end

の「end」の「中に」書くのか? それとも、 「外に」書くのか?

先輩エンジニアの方に聞いて疑問を解決したのですが結論、「外に」書くようです。
下に「誤った書き方」と「正しい書き方」の両方を記載しておきます。

誤った書き方

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

target 'VocaBuilNikki' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  
  # Pods for VocaBuilNikki
  pod 'Firebase'
  pod 'Firebase/Firestore'
  pod 'Firebase/Auth'
  pod 'EMAlertController'
  
  post_install do |installer|
    installer.pods_project.targets.each do |target|
      target.build_configurations.each do |config|
        if `uname -m`.strip == 'arm64'
          config.build_settings['EXCLUDED_ARCHS'] = ''
        else
          config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
        end
      end
    end
  end
  
end

正しい書き方

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

target 'VocaBuilNikki' do
  # Comment the next line if you don't want to use dynamic frameworks
  use_frameworks!
  
  # Pods for VocaBuilNikki
  pod 'Firebase'
  pod 'Firebase/Firestore'
  pod 'Firebase/Auth'
  pod 'EMAlertController'
  
end

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      if `uname -m`.strip == 'arm64'
        config.build_settings['EXCLUDED_ARCHS'] = ''
      else
        config.build_settings['EXCLUDED_ARCHS[sdk=iphonesimulator*]'] = 'arm64'
      end
    end
  end
end

Discussion