LoginSignup
4
3

More than 1 year has passed since last update.

Apple Silicon(M1) 対応の Firebase Unity SDK 作成手順

Last updated at Posted at 2022-04-15

背景

#環境
macOS(12.2.1)
Unity(2021.3.0f1)

手順

SDKのソースコード取得

幸い Firebase はオープンソースなので自分でビルド出来る

公式手順の確認

ビルド準備(オプションの確認)

ビルド

自分は 8.9.0 が欲しかったので、ターミナルで

./build_macos.sh -DFIREBASE_UNITY_SDK_VERSION=8.9.0 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

を実行
cmakeの out-of-sourceビルドが自動で実行され、 macos_unity というフォルダを自動で作ってくれてそこに成果物が吐き出されます
失敗した場合、 macos_unity ディレクトリをまるごと消してやり直します

build_macos.sh を覗くとわかりますが、内部で叩いているのは build_bash.sh です

複数回の実行でかなり時間が掛かったので、自分は build_bash.sh の中の

    # Build the SDK
    make

の箇所を make -j8 に変えてしまいました (出力が若干怪しかったので、時間があるなら並列にしない方が良いかも知れません)

なんかエラー

    from absl import app
ImportError: No module named absl

absl とやらがないらしいので入れる
実行ログを見ると /usr/bin/python を使用している

-- Found PythonInterp: /usr/bin/python (found suitable version "2.7.18", minimum required is "2.7")

pip をアップデートしてくれというメッセージが出たので pip も更新
pip が新しすぎて荷が重い模様なのでバージョン指定で入れた

% /usr/bin/python -m pip install --upgrade pip==20.3
% /usr/bin/python -m pip install absl-py

なんかエラー

ld: warning: ignoring file /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libssl.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64
ld: warning: ignoring file /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libcrypto.a, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

openssl が x86_64のしかないよって言ってる

% lipo -info /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libssl.a
Non-fat file: /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libssl.a is architecture: x86_64
% lipo -info /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libcrypto.a
Non-fat file: /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libcrypto.a is architecture: x86_64

確かに。

OpenSSLの Universal Binary 作成

arm64用のビルド

% ./Configure darwin64-arm64-cc --prefix="/tmp/openssl-arm" no-asm
% make
% make install

x86_64用のビルド

% ./Configure darwin64-x86_64-cc --prefix="/tmp/openssl-x86"
% make
% make install

ここでも自分は make に -j8 つけました

Universal Binary作成

% lipo /tmp/openssl-arm/lib/libssl.a /tmp/openssl-x86/lib/libssl.a -create -output libssl.a

出来たので差し替えて確認

% lipo -info /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libssl.a
Architectures in the fat file: /usr/local/Cellar/openssl@1.1/1.1.1n/lib/libssl.a are: x86_64 arm64

Universal Binary になっている

libcrypto.aの方も同様に作成・差し替える

再度ビルド

./build_macos.sh -DFIREBASE_UNITY_SDK_VERSION=8.9.0 -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64"

出来た

macos_unity ディレクトリに成果物がある

% find . -name "*.bundle"
./macos_unity/database/FirebaseCppDatabase.bundle
./macos_unity/FirebaseCppApp-8_9_0.bundle
./macos_unity/crashlytics/FirebaseCppCrashlytics.bundle
./macos_unity/bin/external/src/firestore-build/external/src/grpc/src/objective-c/tests/TestCertificates.bundle
./macos_unity/firestore/FirebaseCppFirestore.bundle
./macos_unity/auth/FirebaseCppAuth.bundle
./macos_unity/storage/FirebaseCppStorage.bundle
./macos_unity/installations/FirebaseCppInstallations.bundle
./macos_unity/functions/FirebaseCppFunctions.bundle
./macos_unity/remote_config/FirebaseCppRemoteConfig.bundle
./macos_unity/dynamic_links/FirebaseCppDynamicLinks.bundle
./macos_unity/messaging/FirebaseCppMessaging.bundle
./macos_unity/analytics/FirebaseCppAnalytics.bundle

% lipo -info macos_unity/FirebaseCppApp-8_9_0.bundle
Architectures in the fat file: macos_unity/FirebaseCppApp-8_9_0.bundle are: x86_64 arm64

既存ファイル差し替え

自分は .unitypackage ではなく .tgz ファイルを用いて packages/manifest.json へ記述する方法で対応しているので、
com.google.firebase.app-8.9.0.tgz を展開して FirebaseCppApp-8_9_0.bundle を差し替えて再圧縮
他も同様

以上で動きました

4
3
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
4
3