0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CocoaPodsでM1非対応ライブラリをOTHER_LDFLAGSから排除してビルドを通す

Last updated at Posted at 2021-07-20

みなさん もうM1 Macに乗り換えましたよね??メモリ足りなくないですか???と
Google SignInも無事にM1対応のv6へと更新されたらしく、用済み情報になってきた感もありますので以下、公開しときます。

EXCLUDED_ARCHS[sdk=iphonesimulator*] の雑対応で済ませてる人もいるんでしょうが、それじゃsimulator使えなくて不便じゃないです?

CocoaPodsのPodsfileの後処理で、OTHER_LDFLAGSを書き換えてやることでビルド通す方法。

例ではGoogleSignInを消してますが、まだまだ他にも非対応のフレームワークはあるかと思いますので適当に書き換えてどうぞ。

Podfile

...

post_install do |installer|
  installer.pods_project.targets.each do |target|
    target.build_configurations.each do |config|
      # exclude specified frameworks
      puts target.name
      if target.name.start_with? 'Pods-'
        xcconfig_path = config.base_configuration_reference.real_path
        xcconfig = File.read(xcconfig_path).split("\n")
        oldf = xcconfig.filter{|x| x.start_with?("OTHER_LDFLAGS")}.first
        if ! oldf.nil?
          xcconfig.delete(oldf)
          xcconfig.append oldf.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphoneos*] =')
          xcconfig.append oldf.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphonesimulator*][arch=x86_64] =')
          xcconfig.append oldf.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphonesimulator*][arch=i386] =')
          new_oldf = oldf
          ['GoogleSignIn'].each { |lib|
            new_oldf.sub!(" -framework \"#{lib}\"", '')
          }
          xcconfig.append new_oldf.sub('OTHER_LDFLAGS =', 'OTHER_LDFLAGS[sdk=iphonesimulator*][arch=arm*] =')
          File.open(xcconfig_path, "w") { |f| f << xcconfig.join("\n") }
        end
      end
    end
  end
end

解説

xcconfigのOTHER_LDFLAGSをゴリゴリ書き換えてます。
sdk/arch指定で、iphonesimulator*かつarm*の場合には特定frameworkを排除したのを、そうでないのは元々のを指定しています。
ビルド対象によってはappletv*,watch*,macos*を適当に足してあげてください。

これでpod installしてやればリンカのエラーは消えるので、あとはひたすら#ifdefで頑張ってください。

framework名とpodのrepo名は必ずしも一致/一対一対応していないので、エラーメッセージみつつ適当にどうぞ。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?