facebook twitter hatena line email

Unity/GoogleMobileAds/初期設定

提供: 初心者エンジニアの簡易メモ
2019年9月11日 (水) 03:54時点におけるAdmin (トーク | 投稿記録)による版 (GoogleMobileAds-3.16以後)

移動: 案内検索

GoogleMobileAds-3.16以後

GoogleMobileAds-3.16以後は以下設定が必要。

3.18(2019/6/21)からはデフォでadmob/admanager判定コードが入ってた。

Assets/GoogleMobileAds/Resourcesを選択するとフォーム上からAndroidとiOSのappIdを入力できる

androidの場合(admob)

GoogleMobileAds-v3.16からこのファイルにAPPLICATION_IDが存在する。

Assets/Plugins/Android/GoogleMobileAdsPlugin/AndroidManifest.xmlの[ADMOB APPLICATION ID]にadmobのAppIDを入れれば良い

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.unity.ads"
    android:versionName="1.0"
    android:versionCode="1">
  <uses-sdk android:minSdkVersion="14"
      android:targetSdkVersion="19" />
  <application>
    <uses-library android:required="false" android:name="org.apache.http.legacy"/>
    <meta-data
    android:name="com.google.android.gms.ads.APPLICATION_ID"
    android:value="[ADMOB APPLICATION ID]"/>
  </application>
</manifest>


MobileAds.Initialize(appId);は不要となる。 参考:https://developers.google.com/admob/android/quick-start#update_your_androidmanifestxml

java.lang.RuntimeException: Unable to get provider com.google.android.gms.ads.MobileAdsInitProvider: java.lang.IllegalStateException: Invalid application IDが発生するときは [ADMOB APPLICATION ID]がそのままな可能性がある。

iosの場合(admob)

GoogleMobileAds-v3.16からこのファイルは存在する。

Assets/GoogleMobileAds/Editor/PListProcessor.cs

string appId = "ADMOB_APPLICATION_ID";

ADMOB APPLICATION IDにadmobのAppIDを入れれば良い

iosのprojectをビルドし、Info.plistのADMOB_APPLICATION_IDに値が入っていることを確認する。

これを設定しないと以下が発生する

Thread 1: signal SIGABRT
libc++abi.dylib: terminating with uncaught exception of type NSException

androidの場合(Google AdManager)

Assets/Plugins/Android/GoogleMobileAdsPlugin/AndroidManifest.xml

<manifest>
  <application>
    <meta-data
         android:name="com.google.android.gms.ads.AD_MANAGER_APP"
         android:value="true"/>
 </application>
</manifest>

iosの場合(Google AdManager)

Assets/GoogleMobileAds/Editor/PListProcessor.cs のGADApplicationIdentifier行を削除して、GADIsAdManagerApp行を追加。

public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
    string appId = "ADMOB_APPLICATION_ID";
    string plistPath = Path.Combine(path, "Info.plist");
    PlistDocument plist = new PlistDocument();
    plist.ReadFromFile(plistPath);
    plist.root.SetString("GADApplicationIdentifier", appId);
    plist.root.SetBoolean("GADIsAdManagerApp", true);
    File.WriteAllText(plistPath, plist.WriteToString());
}