【Unity × AdMob】iOSビルド時のUndefined symbols: _CGSizeFromGADAdSizeエラーを解消
☀️ 環境情報
- 日時: 2025/01
- MacOS: Sequoia (15.2)
- Unity: 6000.0.32
- Google Mobile Ads for Unity: 9.3
☀️ 問題概要
AdMob を導入した Unity アプリの開発時に、Unity 上でのビルドは成功するが生成された Xcode プロジェクトを用いて iOS 向けにビルドを行うとエラーが多数発生する。
Undefined symbols: _CGSizeFromGADAdSize
Undefined symbols: _GADAdLoaderAdTypeNative
-
Undefined symbols:_GADAdSizeEqualToSize
...
☀️ 解決策概要
この問題は
.xcodeproj
ファイルではなく
.xcworkspace
ファイル
を使用して Xcode でビルドすることで解決する。
Unity のビルド時に .xcworkspace
ファイルが生成されるように CocoaPods 関連の修正を行った。
☀️ 詳細
この問題について調査したところ、以下の解決策を示す記事が多かったが、いずれの方法でも解消できなかった。このため、本記事ではこれらとは異なる方法を紹介する。
- AdMob の再インストール
- Xcode のバージョン更新
- Bitcode を disabeld にする
- Clean Build
1. 事前確認事項
-
Unity ビルドの生成物に
.xcworkspace
ファイルが存在するか確認する。
→.xcworkspace
ファイルがあれば、これを Xcode から開いてビルドすれば良い。 -
CocoaPods がインストールされているか確認する。
$ pod --version
→ バージョンが表示されれば問題ない。
表示されない場合はインストールを行う。
- Unity の Assets > External Dependency Manager > iOS Resolver から CocoaPods Integration が Xcode Workspace に設定されているか確認する。
→ 異なる値になっている場合は修正し、再度ビルドを試す。
CocoaPods Integration がXcode Workspace
形式になっているにもかかわらず、.xcworkspace ファイルが生成されないのは不自然である。
以下、解決手順を示す。
2. 解決手順
まず、ターミナルを開き、Unity のビルド成果物フォルダに移動する。
$ cd {ビルド成果物の path}
つぎに .xcworkspace ファイルを作成するためのコマンドを実行する。
(Podfile が存在しない場合は事前にpod init
を実行する。)
$ pod install
おそらくここで何らかのエラーが発生する。エラー内容を確認し、pod install
が成功するように修正したい。
以下に、筆者の環境で発生したエラーとその解決策を示す。
$ pod install
Analyzing dependencies
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- ffi_c (LoadError)
...
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': dlopen(/Library/Ruby/Gems/2.6.0/gems/ffi-1.17.1-arm64-darwin/lib/2.6/ffi_c.bundle, 0x0009): tried: '/Library/Ruby/Gems/2.6.0/gems/ffi-1.17.1-arm64-darwin/lib/2.6/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64h' or 'x86_64')), '/System/Volumes/Preboot/Cryptexes/OS/Library/Ruby/Gems/2.6.0/gems/ffi-1.17.1-arm64-darwin/lib/2.6/ffi_c.bundle' (no such file), '/Library/Ruby/Gems/2.6.0/gems/ffi-1.17.1-arm64-darwin/lib/2.6/ffi_c.bundle' (mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64h' or 'x86_64')) - /Library/Ruby/Gems/2.6.0/gems/ffi-1.17.1-arm64-darwin/lib/2.6/ffi_c.bundle (LoadError)
...
どうやら ffi に関して、x86_64 版が必要なのに arm 版がインストールされているようなので修正を行う。
Ruby 関連の作業を行うため、事前に rbenv をインストールする。
(Homebrew がインストールされていない場合は事前にインストールする。)
$ brew install rbenv
その後、ffi を再インストールする。
$ sudo gem uninstall ffi
Password:
You have requested to uninstall the gem:
ffi-1.17.1-arm64-darwin
ethon-0.16.0 depends on ffi (>= 1.15.0)
If you remove this gem, these dependencies will not be met.
Continue with Uninstall? [yN] y
Successfully uninstalled ffi-1.17.1-arm64-darwin
$ sudo gem install ffi
Fetching ffi-1.17.1-x86_64-darwin.gem
Successfully installed ffi-1.17.1-x86_64-darwin
Parsing documentation for ffi-1.17.1-x86_64-darwin
Done installing documentation for ffi after 0 seconds
1 gem installed
再度pod install
を実行する。
$ pod install
Analyzing dependencies
Downloading dependencies
Installing Google-Mobile-Ads-SDK (11.11.0)
Installing GoogleUserMessagingPlatform (2.6.0)
Generating Pods project
Integrating client project
[!] Please close any current Xcode sessions and use `Unity-iPhone.xcworkspace` for this project from now on.
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
[!] Found multiple specifications for `Google-Mobile-Ads-SDK (11.11.0)`:
…
成功したように見えるが、warning が表示されているため、対応を行う。
キャッシュを削除して再度インストールする。
$ pod cache clean --all
$ pod install
Analyzing dependencies
Downloading dependencies
Generating Pods project
Integrating client project
Pod installation complete! There are 2 dependencies from the Podfile and 2 total pods installed.
これで .xcworkspace が生成された。
このファイルから iOS ビルドを試すと成功する。一度成功すれば、次回以降は Unity がビルド時に workspace を作成するようになる。
☀️ まとめ
Unity で AdMob を導入した iOS アプリをビルドする際に Undefined symbols エラーが発生する場合は、.xcworkspace ファイルを使用してビルドする必要がある。
Unity のビルドで .xcworkspace ファイルが生成されない場合には、CocoaPods の設定や ffi のインストール状況を確認し、必要に応じて修正を行うことでこの問題を解決できる。
☀️ 参考資料
- Google Mobile Ads Unity Plugin: https://github.com/googleads/googleads-mobile-unity
- CocoaPods: https://cocoapods.org/
Discussion