質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

Q&A

解決済

1回答

4094閲覧

unity iOS Admodで広告を入れたい

itsuki2017

総合スコア2

AdMob

AdMobは、事前に指定した条件に従ってアプリに広告を表示するGoogleのサービス。開発者の向けのサービスで、広告を掲載することにより、収益を得ることが可能です。その他、見た目や雰囲気などアプリに合う広告に変更したり、広告表示の場所を指定することもできます。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

Xcode

Xcodeはソフトウェア開発のための、Appleの統合開発環境です。Mac OSXに付随するかたちで配布されています。

Unity

Unityは、Unity Technologiesが開発・販売している、IDEを内蔵するゲームエンジンです。主にC#を用いたプログラミングでコンテンツの開発が可能です。

iPhone

iPhoneとは、アップル社が開発・販売しているスマートフォンです。 同社のデジタルオーディオプレーヤーiPodの機能、電話機能、インターネットやメールなどのWeb通信機能の3つをドッキングした機器です。

0グッド

0クリップ

投稿2020/08/30 14:42

編集2020/10/11 08:56

前提・実現したいこと

unityでiOSゲームアプリを作成しiphoneでゲームを問題なくプレイするところまで行きました。
その後Admodで広告を表示させようとしました。

発生している問題・エラーメッセージ

Admobの設定後ビルドするところまでは問題ないように思えたのですが
アプリを立ち上げるためにタップすると一瞬だけホーム画面上で画面が薄暗くなるだけで
ゲームアプリが起動しません。すぐに通常のホーム画面に戻ります。
スプラッシュ画面前でクラッシュします。

エラー表示なし

該当のソースコード

using System.Collections; using System.Collections.Generic; using UnityEngine; using GoogleMobileAds.Api; public class GoogleAds : MonoBehaviour { // Use this for initialization void Start() { #if UNITY_ANDROID string appId = "ca-app-pub-3940256099942544~3347511713"; #elif UNITY_IPHONE string appId = "ここには自分で取得したアプリIDを貼り付け"; #else string appId = "unexpected_platform"; #endif // Initialize the Google Mobile Ads SDK. MobileAds.Initialize(appId); RequestBanner(); } private void RequestBanner() { #if UNITY_ANDROID string adUnitId = "ca-app-pub-3940256099942544/6300978111"; #elif UNITY_IPHONE string adUnitId = "ここには自分で取得した広告ユニットIDを貼り付け"; #else string adUnitId = "unexpected_platform"; #endif // Create a 320x50 banner at the top of the screen. BannerView bannerView = new BannerView(adUnitId, AdSize.Banner, AdPosition.Bottom); // Create an empty ad request. AdRequest request = new AdRequest.Builder().Build(); // Load the banner with the request. bannerView.LoadAd(request); } }

試したこと

https://simanezumi1989.hatenablog.com/entry/2020/03/17/175109
https://developers.google.com/admob/ios/quick-start?hl=ja
上記のサイト(動画)を参考にさせていただきました。

GoogleMobileAds-v5.0.1.unitypackage
をインストール。

GoogleMobileAds.framework
GoogleAppMeasurement.framework
GoogleUtilities.framework
nanopb.framework

https://edunity.hatenablog.com/entry/20200128/1580144428
の、サイトを参考にAssetsのPluginsフォルダ内のiOSフォルダに入れました。
初めは
GoogleUtilities.xcframework と
nanopb.xcframework
を間違えてフォルダーに入れてしまいましたが
https://picxpic.com/?p=3764 のサイト参考に
フォルダーの中にios-armv7_arm64がありその中の
GoogleUtilities.framework
nanopb.frameworkを入れました。

UnityのAssets→Google Mobile Ads→Settings を開き
Enabled にチェックを入れてAdMob App IDを入力。
Androidにはテスト用のアプリIDを入れています。
iOSには自分で取得したアプリIDを入れています。

Assets → iOSResolver → Settings → Cocoapods Integration を
Xcode Project - Add Cocoapods to the Xcode Project に変更

Assets → Play Services Resolver → iOS Resolver → InstallCocoapods をクリック

該当のソースコードをメインシーンの空のオブジェクトに適用

UnityでiOSようにビルドしたデーターをUSBでMacBookに移動。

https://developers.google.com/admob/ios/quick-start?hl=ja の
「プロジェクトのビルド設定で、以下のように [Other Linker Flags] に -ObjC リンカー フラッグを追加します。」

「Info.plist を更新する」を実施後
iphoneにビルドしました。

しかしアプリを起動しようとしても一瞬だけ画面が薄暗くなるだけで
起動しません。

https://qiita.com/VeyronSakai/items/2c3b01ba6dfed84c3405
のサイトを参考にしようとしましたが
Assets/GoogleMobileAds/Editor ディレクトリで PListProcessor.cs を開いても
「ADMOB_APPLICATION_ID」というのがなく試せません。

#if UNITY_IPHONE || UNITY_IOS using System.IO; using UnityEditor; using UnityEditor.Callbacks; using UnityEditor.iOS.Xcode; using GoogleMobileAds.Editor; public static class PListProcessor { [PostProcessBuild] public static void OnPostProcessBuild(BuildTarget buildTarget, string path) { string plistPath = Path.Combine(path, "Info.plist"); PlistDocument plist = new PlistDocument(); plist.ReadFromFile(plistPath); if (!GoogleMobileAdsSettings.Instance.IsAdManagerEnabled && !GoogleMobileAdsSettings.Instance.IsAdMobEnabled) { NotifyBuildFailure("Neither Ad Manager nor AdMob is enabled yet."); } if (GoogleMobileAdsSettings.Instance.IsAdManagerEnabled) { plist.root.SetBoolean("GADIsAdManagerApp", true); } if (GoogleMobileAdsSettings.Instance.IsAdMobEnabled) { string appId = GoogleMobileAdsSettings.Instance.AdMobIOSAppId; if (appId.Length == 0) { NotifyBuildFailure( "iOS AdMob app ID is empty. Please enter a valid app ID to run ads properly."); } else { plist.root.SetString("GADApplicationIdentifier", appId); } } if (GoogleMobileAdsSettings.Instance.DelayAppMeasurementInit) { plist.root.SetBoolean("GADDelayAppMeasurementInit", true); } File.WriteAllText(plistPath, plist.WriteToString()); } private static void NotifyBuildFailure(string message) { string prefix = "[GoogleMobileAds] "; bool openSettings = EditorUtility.DisplayDialog( "Google Mobile Ads", "Error: " + message, "Open Settings", "Close"); if (openSettings) { GoogleMobileAdsSettingsEditor.OpenInspector(); } #if UNITY_2017_1_OR_NEWER throw new BuildPlayerWindow.BuildMethodException(prefix + message); #else throw new OperationCanceledException(prefix + message); #endif } } #endif

補足情報(FW/ツールのバージョンなど)

アプリ作成はWindowsでしています。
Windows 10 Pro バージョン1903
Unity 2019.3.9f1
GoogleMobileAds-v5.0.1
GoogleMobileAdsSdkiOS-7.64.0

MacBook Air 11インチEarly2015
MacOS Catalina バージョン10.15.6
Xcode バージョン11.6(11E708)

iPhoneXR iOS13.5.1

ご教示いただければ幸いです。

Xcode クラッシュレポート

#import "PLCrashReporter.h" #import "CrashReporter.h" #include "UndefinePlatforms.h" #include <mach-o/ldsyms.h> #include "RedefinePlatforms.h" extern "C" NSString* UnityGetCrashReportsPath(); static NSUncaughtExceptionHandler* gsCrashReporterUEHandler = NULL; static decltype(_mh_execute_header) * sExecuteHeader = NULL; extern "C" void UnitySetExecuteMachHeader(const decltype(_mh_execute_header)* header) { sExecuteHeader = header; } extern "C" const decltype(_mh_execute_header) * UnityGetExecuteMachHeader() { return sExecuteHeader; } static void SavePendingCrashReport() { if (![[UnityPLCrashReporter sharedReporter] hasPendingCrashReport]) return; NSFileManager *fm = [NSFileManager defaultManager]; NSError *error; if (![fm createDirectoryAtPath: UnityGetCrashReportsPath() withIntermediateDirectories: YES attributes: nil error: &error]) { ::printf("CrashReporter: could not create crash report directory: %s\n", [[error localizedDescription] UTF8String]); return; } NSData *data = [[UnityPLCrashReporter sharedReporter] loadPendingCrashReportDataAndReturnError: &error]; if (data == nil) { ::printf("CrashReporter: failed to load crash report data: %s\n", [[error localizedDescription] UTF8String]); return; } NSString* file = [UnityGetCrashReportsPath() stringByAppendingPathComponent: @"crash-"]; unsigned long long seconds = (unsigned long long)[[NSDate date] timeIntervalSince1970]; file = [file stringByAppendingString: [NSString stringWithFormat: @"%llu", seconds]]; file = [file stringByAppendingString: @".plcrash"]; if ([data writeToFile: file atomically: YES]) { ::printf("CrashReporter: saved pending crash report.\n"); if (![[UnityPLCrashReporter sharedReporter] purgePendingCrashReportAndReturnError: &error]) { ::printf("CrashReporter: couldn't remove pending report: %s\n", [[error localizedDescription] UTF8String]); } } else { ::printf("CrashReporter: couldn't save crash report.\n"); } // Now copy out a pending version that we can delete if/when we send it file = [UnityGetCrashReportsPath() stringByAppendingPathComponent: @"crash-pending.plcrash"]; if ([data writeToFile: file atomically: YES]) { ::printf("CrashReporter: saved copy of pending crash report.\n"); } else { ::printf("CrashReporter: couldn't save copy of pending crash report.\n"); } } static void InitCrashReporter() { NSError *error; UnityInstallPostCrashCallback(); if ([[UnityPLCrashReporter sharedReporter] enableCrashReporterAndReturnError: &error]) ::printf("CrashReporter: initialized\n"); else NSLog(@"CrashReporter: could not enable crash reporter: %@", error); SavePendingCrashReport(); } static void UncaughtExceptionHandler(NSException *exception) { NSLog(@"Uncaught exception: %@: %@\n%@", [exception name], [exception reason], [exception callStackSymbols]); if (gsCrashReporterUEHandler) gsCrashReporterUEHandler(exception); } static void InitObjCUEHandler() { // Crash reporter sets its own handler, so we have to save it and call it manually gsCrashReporterUEHandler = NSGetUncaughtExceptionHandler(); NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler); } void InitCrashHandling() { #if ENABLE_CUSTOM_CRASH_REPORTER InitCrashReporter(); #endif #if ENABLE_OBJC_UNCAUGHT_EXCEPTION_HANDLER InitObjCUEHandler(); #endif } // This function will be called when AppDomain.CurrentDomain.UnhandledException event is triggered. // When running on device the app will do a hard crash and it will generate a crash log. extern "C" void CrashedCheckBelowForHintsWhy() { #if ENABLE_IOS_CRASH_REPORTING || ENABLE_CUSTOM_CRASH_REPORTER // Make app crash hard here __builtin_trap(); // Just in case above doesn't work abort(); #endif }

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

U_U_Jenkins

2020/10/07 11:20

まだ、困っているのなら…。 Xcodeのデバッグ機能を使ってアプリをテストしてみてください。 ログに表示されるテキストの掲載をお願いします。
itsuki2017

2020/10/11 09:25

お返事いただいたのに連絡遅れ申し訳ございません。。 現状解決はしておりません。 「Xcode クラッシュレポート」として本文に追加いたしました。 Xcodeのデバッグ機能がわからずこれでよろしいのでしょうか。 「Xcode クラッシュレポート」の gsCrashReporterUEHandler(exception); の部分に Thread 5: "The Google Mobile Ads SDK was initialized without AppMeasurement. Google AdMob publishers, follow instructions here: https://googlemobileadssdk.page.link/admob-ios-update-plist to include the AppMeasurement framework and set the -ObjC linker flag. Google Ad Manager publishers, follow instructions here: https://googlemobileadssdk.page.link/ad-manager-ios-update-plist" とエラー?がありました。 「フレームワークを含め、-ObjCリンカーを設定します」 と書いてありますがこれは設定はしてあります。 これで何かヒントになりますでしょうか。
itsuki2017

2020/10/13 22:05

https://developers.google.com/admob/ios/quick-start?hl=ja の 「Info.plist を更新する」→「または、プロパティ リスト エディタで編集することもできます。」と 同じことであれば試しています。 念のために「該当のソースコード」の #elif UNITY_IPHONE string appId = "ここには自分で取得したアプリIDを貼り付け"; と 「試したこと」の 「UnityのAssets→Google Mobile Ads→Settings を開き Enabled にチェックを入れてAdMob App IDを入力。 Androidにはテスト用のアプリIDを入れています。 iOSには自分で取得したアプリIDを入れています。」 と https://program-life.com/1125 を 再度グーグルAdMobサイトからIOS用アプリIDコピーし貼り付け直しましたが 変わりませんでした…… 完全に新しくunityでプロジェクト作って 初期状態で広告が出るか試していなかったので 自分の手順があっているのか確認中です。
itsuki2017

2020/10/18 08:57 編集

新しくunityでプロジェクト作って試しましたが 同じ症状でアプリが起動しませんでした。 私の手順が間違っている可能性が高く 一から見直します。(何度も見直しているのですがどこが悪いのか…) unityadsは正常に動きましたので 今回のゲームはunityadsをつけてAppleに申請中です。 Admodのほうは、このままだと心が折れてしまいそうなのでw 一旦別のゲームの開発に身を置こうと思います。 しばらくしたらそこでまた一からAdmodの手順を見ながらやってみようと思います。
guest

回答1

0

ベストアンサー

こんばんは。お力になれるかはわかりませんが、
・admobのプラグインなどを一旦全て外してからビルドすると、アプリは立ち上がりますか?立ち上がらないのならそもそも原因はadmobでは無いと思います。確かに広告系が原因で落ちることもありますが、案外別の箇所のエラーが原因だったりすることもあります。
・MacBookにUnityをインストールし、そこでビルドしてみるとうまくいくかもしれません。

アプリ開発大変ですよね、お互い楽しみながら頑張りましょう。

投稿2020/10/14 15:50

hakhak

総合スコア32

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

itsuki2017

2020/10/18 08:18

ご回答励ましありがとうございます。 AdMobを外すと正常にiphoneでゲームできます。 MacBookにunityも視野に入れてみます。 少しずつ進んでいきます。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問