LoginSignup
2
1

More than 1 year has passed since last update.

広告SDKを統合したiOS向けUnityビルドをApp化するまでに遭遇したエラー

Last updated at Posted at 2023-03-15

Unityで作ったゲームでHyper Casual Game向けにSupersonicで必要となるSDKを統合してiOS向けビルドを行いました。
Xcodeプロジェクトをそのままビルドしてアプリ化するまでに起こったエラーと解決策をまとめます。

ビルド環境

・以下のUnity SDKを統合
Facebook, AppsFlyer, GameAnalytics
・WindowsでUnityをiOS向けのビルド
・MacbookでXcodeプロジェクトをビルド

ビルドに必要なファイルがなくてビルドエラーを起こす。

エラーコード:
FBUnityInterface.mm 'FBSDKCoreKit/FBSDKCoreKit.h' file not found

ビルドに必要なファイルないので集める必要があります。
今回のエラー内容はFacebook向けのものが足りませんが、Unityでビルドした段階ではAppsFlyer, GameAnalyticsのSDKのビルドタイミングで同じような内容のエラーが出るので必要なファイルを集めまる必要があります。

CocoaPodsで必要なライブラリを集める

Xcodeプロジェクトフォルダを見るとPodfileがあり、そこに必要なライブラリが書かれています。
(ない場合は作る必要があるがUnityでビルドした場合はあると思われます)
以下の作業をターミナルで行います。
(作業を行う前にXcodeは閉じてください)

  1. CocoaPodsをインストールする
    $ sudo gem install cocoapods
  2. 初期セットアップ
    $ pod setup
  3. プロジェクトフォルダに移動する(例)
    $ cd /Users/user/Desktop/XcodeBuildTest/
  4. ライブラリをインストールする(Podfileがない場合は作る必要があります)
    $ pod install

インストールでエラーが出た場合は以下を試してから再度インストールしてください。
$ pod update

それでもエラーが出る場合:Bus Error at 0x00000001051f4000
intelのCPUでは問題が起きていませんが、M1などMacのCPUだとエラーが出るようです。
ターミナルから以下のコマンドを実行します。
$ gem install --user-install ffi -- --enable-libffi-alloc

参考:
https://stackoverflow.com/questions/68553842/error-installing-a-pod-bus-error-at-0x00000001045b8000

インストールが完了すると以下のプロジェクトフォルダに以下のファイルができます。
Unity-iPhone.xcworkspace
このファイルでXcodeを開くと左側のナビゲーターにUnity-iPhoneの下にPodsが追加されます。
Podsが追加されているのを確認したらXcodeで再度ビルドします。

does not contain bitcode.

エラーコード:
'/Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-envkqihsknqcxhfguhvskqfjbnqp/Build/Products/ReleaseForRunning-iphoneos/FBAEMKit/FBAEMKit.framework/FBAEMKit' does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file '/Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-envkqihsknqcxhfguhvskqfjbnqp/Build/Products/ReleaseForRunning-iphoneos/FBAEMKit/FBAEMKit.framework/FBAEMKit' for architecture arm64

解決方法:
XcodeのBuild Settings -> Build Options -> Enable BitcodeNoにセットします。

注意点としてTARGETSUnity-iPhone, Unity-iPhone Tests, UnityFrameworkと並んでいますが、ターゲット毎にBitcodeをNoに設定しないと同じエラーが出ます。
念の為PROJECTUnity-iPhoneもBitcodeがNoになっていることを確認してみてください。

Command PhaseScriptExecution failed with a nonzero exit code

エラーコード:
Command PhaseScriptExecution failed with a nonzero exit code
ナビゲータに表示されている情報が少なすぎるのナビゲータのリストアイコンShow the Report navigatorを選択します。
スクリーンショット 2023-03-15 10.46.49.png
エラーの詳細:
Showing Recent Issues /Users/user/Library/Developer/Xcode/DerivedData/Unity-iPhone-envkqihsknqcxhfguhvskqfjbnqp/Build/Intermediates.noindex/Unity-iPhone.build/ReleaseForRunning-iphoneos/UnityFramework.build/Script-9D3DC87A221D90AB00B2960B.sh: line 2: /Users/user/Desktop/Xcode/XcodeBuildTest/MapFileParser.sh: Permission denied

MapFileParser.shのファイルを実行するためのパーミッションが足りないことがわかります。

解決方法:
ターミナルでファイルの場所に移動して実行権限を追加する。
$ chmod +x MapFileParser.sh

起動直後にアプリが落ちる

エラーコード:
UnityFramework [access] This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSUserTrackingUsageDescription key with a string value explaining to the user how the app uses this data.

エラーコードはiPhoneをMacに繋いだままXcodeのデバッグウィンドウで確認します。

Info.plistNSUserTrackingUsageDescriptionのkeyを追記する必要があることがわかります。
毎回Info.plistに追記するのは面倒なのでUnityでビルドするときに追記されるようにします。

以下エディタ用のスクリプトをAssets/Scripts/Editorなどに配置します。

PostBuildStep.cs
using UnityEditor;
using UnityEditor.Callbacks;
#if UNITY_IOS
using UnityEditor.iOS.Xcode;
#endif
using System.IO;
 
public class PostBuildStep {
    // Set the IDFA request description:
    const string k_TrackingDescription = "Your data will be used to provide you a better and personalized ad experience.";
 
    [PostProcessBuild(0)]
    public static void OnPostProcessBuild(BuildTarget buildTarget, string pathToXcode) {
        if (buildTarget == BuildTarget.iOS) {
            AddPListValues(pathToXcode);
        }
    }
 
    // Implement a function to read and write values to the plist file:
    static void AddPListValues(string pathToXcode) {
        // Retrieve the plist file from the Xcode project directory:
        string plistPath = pathToXcode + "/Info.plist";
        PlistDocument plistObj = new PlistDocument();
 
 
        // Read the values from the plist file:
        plistObj.ReadFromString(File.ReadAllText(plistPath));
 
        // Set values from the root object:
        PlistElementDict plistRoot = plistObj.root;
 
        // Set the description key-value in the plist:
        plistRoot.SetString("NSUserTrackingUsageDescription", k_TrackingDescription);
 
        // Save changes to the plist:
        File.WriteAllText(plistPath, plistObj.WriteToString());
    }
}

参考
https://docs.unity.com/ads/en/manual/ATTCompliance

2
1
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
2
1