LoginSignup
9
8

More than 5 years have passed since last update.

AdMobを入れたUnityプロジェクトがUnity Cloud Build上でビルドエラーになるときの対処法

Last updated at Posted at 2017-01-03

確認環境

事象

Unityで作ったアプリにAdMobを表示させるためにGoogle Mobile Ads Unity Pluginを導入しようとしましたが、Unity Cloud Build上でiOSをビルドすると以下のエラーが発生します。(Androidのビルドは正常にできます)

log1.txt
2479: [Unity] 'pod' command not found; unable to generate a usable Xcode project. You can install cocoapods with the Ruby gem package manager:
2480: [Unity]  > sudo gem install -n /usr/local/bin cocoapods
2481: [Unity]  > pod setup
log2.txt
2491: [Unity] Error running cocoapods. Please ensure you have at least version  1.0.0.  You can install cocoapods with the Ruby gem package manager:
2492: [Unity]  > sudo gem install -n /usr/local/bin cocoapods
2493: [Unity]  > pod setup
2494: [Unity] 'pod --version' returned status: 1
2495: [Unity] output:

原因

Google Mobile Ads Unity Pluginの内部でiOSのライブラリの依存関係を管理するためにCocoaPodsを使用していますが、Unity Cloud Build上ではCocoaPodsが使えないのが原因です。

解決策

あくまでも暫定対応ですが、Assets/GoogleMobileAds/Editor/AdMobDependencies.csの53〜63行目あたりをコメントアウトし、スクリプトでライブラリの依存関係を解決しないように変更します。

AdMobDependencies.cs
#elif UNITY_IOS
//        Type iosResolver = Google.VersionHandler.FindClass(
//            "Google.IOSResolver", "Google.IOSResolver");
//        if (iosResolver == null) {
//            return;
//        }
//        Google.VersionHandler.InvokeStaticMethod(
//            iosResolver, "AddPod",
//            new object[] { "Google-Mobile-Ads-SDK" },
//            namedArgs: new Dictionary<string, object>() {
//                { "version", "7.13+" }
//            });
#endif  // UNITY_IOS

上記をコメントアウトすることにより、手動でGoogle Mobile Ads SDKを導入する必要が出てくるため、UnityプロジェクトのAssets/Plugins/iOS内にGoogleMobileAds.frameworkを配置します。

最後にXcodeプロジェクトのEnable Modules (C and Objective-C)YESに自動で設定するために、以下のPostProcessBuildのスクリプトをAssets/Editorあたりに配置してください。(EditorフォルダはUnityでは特殊なフォルダとして扱われます。詳細はこちらを参照してください)

XcodePostProcessBuild.cs
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEditor.iOS.Xcode;

public static class XcodePostProcessBuild
{
    [PostProcessBuild]
    public static void OnPostProcessBuild(BuildTarget target, string path)
    {
        if (target != BuildTarget.iOS)
        {
            return;
        }

        var project = new PBXProject();
        project.ReadFromFile(PBXProject.GetPBXProjectPath(path));

        var projectGuid = project.TargetGuidByName(PBXProject.GetUnityTargetName());
        // Enable Modules (C and Objective-C)をYESに設定する
        project.SetBuildProperty(projectGuid, "CLANG_ENABLE_MODULES", "YES");

        project.WriteToFile(PBXProject.GetPBXProjectPath(path));
    }
}

image

これでUnity Cloud Build上でもiOSのビルドが通るようになります。

参考

9
8
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
9
8