「Unity/GoogleMobileAds/初期設定」の版間の差分
(→"AndroidJavaException: java.lang.ClassNotFoundException: com.google.unity.ads.UnityAdListener"エラー) |
|||
(同じ利用者による、間の7版が非表示) | |||
行2: | 行2: | ||
GoogleMobileAds-3.16以後は以下設定が必要。 | GoogleMobileAds-3.16以後は以下設定が必要。 | ||
− | ===androidの場合=== | + | 3.18(2019/6/21)からはデフォでadmob/admanager判定コードが入ってた。 |
+ | |||
+ | Assets/GoogleMobileAds/Resources/GoogleMobileAdsSettingsを選択するとフォーム上からAndroidとiOSのappIdを入力できる | ||
+ | |||
+ | ===androidの場合(admob)=== | ||
GoogleMobileAds-v3.16からこのファイルにAPPLICATION_IDが存在する。 | GoogleMobileAds-v3.16からこのファイルにAPPLICATION_IDが存在する。 | ||
行30: | 行34: | ||
[ADMOB APPLICATION ID]がそのままな可能性がある。 | [ADMOB APPLICATION ID]がそのままな可能性がある。 | ||
− | ===iosの場合=== | + | ===iosの場合(admob)=== |
GoogleMobileAds-v3.16からこのファイルは存在する。 | GoogleMobileAds-v3.16からこのファイルは存在する。 | ||
行42: | 行46: | ||
Thread 1: signal SIGABRT | Thread 1: signal SIGABRT | ||
libc++abi.dylib: terminating with uncaught exception of type NSException | libc++abi.dylib: terminating with uncaught exception of type NSException | ||
+ | |||
+ | ===androidの場合(Google AdManager)=== | ||
+ | Assets/Plugins/Android/GoogleMobileAdsPlugin/AndroidManifest.xml | ||
+ | <pre> | ||
+ | <manifest> | ||
+ | <application> | ||
+ | <meta-data | ||
+ | android:name="com.google.android.gms.ads.AD_MANAGER_APP" | ||
+ | android:value="true"/> | ||
+ | </application> | ||
+ | </manifest> | ||
+ | </pre> | ||
+ | ===iosの場合(Google AdManager)=== | ||
+ | Assets/GoogleMobileAds/Editor/PListProcessor.cs のGADApplicationIdentifier行を削除して、GADIsAdManagerApp行を追加。 | ||
+ | <pre> | ||
+ | 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()); | ||
+ | } | ||
+ | </pre> | ||
+ | |||
+ | =="AndroidJavaException: java.lang.ClassNotFoundException: com.google.unity.ads.UnityAdListener"エラー== | ||
+ | unity/Build Settings/Player Setting/Publishing Settings/user proguard fileをon | ||
+ | |||
+ | Assets/Plugins/Android/proguard-user.txt に以下を記述 | ||
+ | <pre> | ||
+ | -keep class com.google.unity.** { | ||
+ | *; | ||
+ | } | ||
+ | -keep public class com.google.android.gms.ads.**{ | ||
+ | public *; | ||
+ | } | ||
+ | -keep public class com.google.ads.**{ | ||
+ | public *; | ||
+ | } | ||
+ | -keepattributes *Annotation* | ||
+ | -dontobfuscate | ||
+ | </pre> | ||
+ | |||
+ | 参考:https://stackoverflow.com/questions/53977246/unity-admob-classnotfound-com-google-unity-ads-unityadlistener |
2019年9月11日 (水) 21:08時点における版
目次
GoogleMobileAds-3.16以後
GoogleMobileAds-3.16以後は以下設定が必要。
3.18(2019/6/21)からはデフォでadmob/admanager判定コードが入ってた。
Assets/GoogleMobileAds/Resources/GoogleMobileAdsSettingsを選択するとフォーム上から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()); }
"AndroidJavaException: java.lang.ClassNotFoundException: com.google.unity.ads.UnityAdListener"エラー
unity/Build Settings/Player Setting/Publishing Settings/user proguard fileをon
Assets/Plugins/Android/proguard-user.txt に以下を記述
-keep class com.google.unity.** { *; } -keep public class com.google.android.gms.ads.**{ public *; } -keep public class com.google.ads.**{ public *; } -keepattributes *Annotation* -dontobfuscate