LoginSignup
7
5

More than 3 years have passed since last update.

【Unity】AdMobを入れるとアプリが起動できなくなった時に試したこと

Last updated at Posted at 2019-04-22

状況

AdMobを利用するためにGoogleMobileAds.unitypackage
をインポートした後、Unity上でエラーもなく、実機テストをする際にBuild and Runも通るが、実機でアプリを起動する際に何も反応しない。(アプリをタップした直後にクラッシュしている?)

解決法

android

Assets/Plugin/Android/GoogleMobileAdsPlugin ディレクトリでAndroidManifest.xmlをテキストエディタ等で開き、

<manifest>
    <application>
        <!-- Your AdMob app ID will look similar to this
        sample ID: ca-app-pub-3940256099942544~3347511713 -->
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="YOUR_ADMOB_APP_ID"/>
    </application>
</manifest>

"YOUR_ADMOB_APP_ID"と書いてある部分にAdMob IDを記入する。

ios

Assets/GoogleMobileAds/Editor ディレクトリで PListProcessor.cs を開き、

[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget buildTarget, string path)
{
    // Replace with your iOS AdMob app ID. Your AdMob app ID will look
    // similar to this sample ID: ca-app-pub-3940256099942544~1458002511
    string appId = "ADMOB_APPLICATION_ID";

    string plistPath = Path.Combine(path, "Info.plist");
    PlistDocument plist = new PlistDocument();

    plist.ReadFromFile(plistPath);
    plist.root.SetString("GADApplicationIdentifier", appId);
    File.WriteAllText(plistPath, plist.WriteToString());
}

"ADMOB_APPLICATION_ID"の部分にAdMob IDを記入する。


(参考)
スタートガイド  |  Unity  |  Google Developers

7
5
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
7
5