Решил встроить в игру AdMob, добавил, написал класс для показа рекламы, сбилдил, у меня все работает. Обновил версию игры в Google Play, друг скачал и у него крашнулась игра, выдав такую ошибку:
Вопрос в том как её устранить?
Мой код:
using UnityEngine;
using GoogleMobileAds.Api;
using System;
public class AdmobRewardedVideoHelper : MonoBehaviour
{
[SerializeField]
private GameCore core;
[SerializeField]
private const string adUnitId = "/* id */";
[SerializeField]
private RewardedAd rewardedAd;
[SerializeField]
private AnalyticsHelper analytics;
[SerializeField]
private BonusesHelper bonusesHelper;
[SerializeField]
private int type;
void Start()
{
core = FindObjectOfType<GameCore>();
bonusesHelper = FindObjectOfType<BonusesHelper>();
analytics = FindObjectOfType<AnalyticsHelper>();
// Initialize the Google Mobile Ads SDK.
MobileAds.Initialize(initStatus => { Debug.Log("[AdmobRewardedVideoHelper] - MobileAds.Initialize - initStatus -> " + initStatus); });
RewardedAdRequest();
}
private void RewardedAdRequest()
{
rewardedAd = new RewardedAd(adUnitId);
// Called when an ad request has successfully loaded.
rewardedAd.OnAdLoaded += HandleRewardedAdLoaded;
// Called when an ad request failed to load.
rewardedAd.OnAdFailedToLoad += HandleRewardedAdFailedToLoad;
// Called when an ad is shown.
rewardedAd.OnAdOpening += HandleRewardedAdOpening;
// Called when an ad request failed to show.
rewardedAd.OnAdFailedToShow += HandleRewardedAdFailedToShow;
// Called when the user should be rewarded for interacting with the ad.
rewardedAd.OnUserEarnedReward += HandleUserEarnedReward;
// Called when the ad is closed.
rewardedAd.OnAdClosed += HandleRewardedAdClosed;
// Create an empty ad request.
AdRequest request = new AdRequest.Builder().Build();
// Load the rewarded ad with the request.
rewardedAd.LoadAd(request);
}
private void HandleRewardedAdClosed(object sender, EventArgs e)
{
Debug.Log("[AdmobRewardedVideoHelper] - HandleRewardedAdClosed -> Ad Closed");
RewardedAdRequest();
}
private void HandleUserEarnedReward(object sender, Reward e)
{
switch (type)
{
case 1:
bonusesHelper.GetReward();
break;
case 2:
core.tasks.taskType = 0;
analytics.TaskSkipAnalyticsHanlder();
break;
}
Debug.Log("[AdmobRewardedVideoHelper] - HandleUserEarnedReward -> Ad Earned Reward");
}
private void HandleRewardedAdFailedToShow(object sender, AdErrorEventArgs e)
{
Debug.Log("[AdmobRewardedVideoHelper] - HandleRewardedAdFailedToShow -> Ad Failed To Show");
RewardedAdRequest();
}
private void HandleRewardedAdOpening(object sender, EventArgs e)
{
Debug.Log("[AdmobRewardedVideoHelper] - HandleRewardedAdOpening -> Ad Opening");
}
private void HandleRewardedAdFailedToLoad(object sender, AdErrorEventArgs e)
{
Debug.Log("[AdmobRewardedVideoHelper] - HandleRewardedAdFailedToLoad -> Ad Not Loaded");
RewardedAdRequest();
}
private void HandleRewardedAdLoaded(object sender, EventArgs e)
{
Debug.Log("[AdmobRewardedVideoHelper] - HandleRewardedAdLoaded -> Ad Loaded");
}
public void WatchAd(int type)
{
this.type = type;
if (rewardedAd.IsLoaded())
{
rewardedAd.Show();
}
}
}
Манифест:
<?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">
<application>
<uses-library android:required="false" android:name="org.apache.http.legacy" />
<activity android:name="com.unity3d.player.UnityPlayerNativeActivity" android:label="BitClicker">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
<meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
</activity>
<meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="" />
</application>
</manifest>
Пришлось вручную вписать название игры, тк Unity во время компиляции не мола найти ссылку на строковый ресурс.