Good day!
Help me please. A lot of errors have appeared in the last week:
java.lang.Error: FATAL EXCEPTION [main]
Unity version : 2020.3.8f1
Device model : ZTE ZTE T610
Device fingerprint: ZTE/P809A20/P809A20:5.1.1/LMY47V/20151126.131543:user/release-keys
Build Type : Release
Scripting Backend : IL2CPP
ABI : armeabi-v7a
Strip Engine Code : true
Caused by
at com.unity3d.services.ads.operation.load.LoadModule$2.run (LoadModule.java:114)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:135)
at android.app.ActivityThread.main (ActivityThread.java:5255)
at java.lang.reflect.Method.invoke (Native Method)
at java.lang.reflect.Method.invoke (Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:902)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:697)
With what it can be connected?
I suspect that the error appeared after integrating the unity ad into the game (this is not certain)
Confirmed that there is a problem with ad unity. When I turn off initiation or loading, the problem disappears.
Module code with ads (though I don’t hope that someone will read it)
using UnityEngine;
using GoogleMobileAds.Api;
using GoogleMobileAds.Common;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
using System.Collections;
using TMPro;
public class Ads : MonoBehaviour
{
private InterstitialAd interstitialAd;
private RewardedAd rewardedAd;
private bool isHandleInitCompleteAction, isInterstitialOnAdClosed, isInterstitialOnAdFailedToLoad, isOnAdFailedToLoad, isRewardedOnAdClosed, isRewardedOnUserEarnedReward, isRewardedOnAdFailedToLoad, isRewardedOnAdLoaded;
private bool isRewardedLoadingNow;
private bool isInterstitialLoadingNow;
static public int LevelsWithoutAdvertising = 4;
public bool isShowInterstitialAd;
public Image ButtonBuyFreeImage;
public Button ButtonBuyFree;
public TextMeshProUGUI ButtonBuyFreeText;
public TextMeshProUGUI ButtonBuyFreeTextTime;
public GameObject window;
private bool isPause;
private bool isTimerEnable;
private bool isAdsCoinsAvailableAlways = true;
System.DateTime GetAdsCoinsTime;
void Start()
{
isHandleInitCompleteAction = false;
isInterstitialOnAdClosed = false;
isInterstitialOnAdFailedToLoad = false;
isOnAdFailedToLoad = false;
isRewardedOnAdClosed = false;
isRewardedOnUserEarnedReward = false;
isRewardedOnAdFailedToLoad = false;
isRewardedOnAdLoaded = false;
isRewardedLoadingNow = false;
isInterstitialLoadingNow = false;
// Initialize the Google Mobile Ads SDK.
try
{
MobileAds.Initialize(HandleInitCompleteAction);
}
catch {}
GetAdsCoinsTime = GetTime();
if (!isAdsCoinsAvailableAlways)
if (GetAdsCoinsTime > System.DateTime.Now.AddHours(1))
SetTime();
SetPauseEnable(false);
isTimerEnable = false;
ButtonAdsUpdate();
}
void Update()
{
if (isHandleInitCompleteAction)
{
isHandleInitCompleteAction = false;
LoadAds();
}
if (isInterstitialOnAdClosed)
{
isInterstitialOnAdClosed = false;
Analytics.AdsLevelEnd();
RequestAndLoadInterstitialAd();
}
if (isInterstitialOnAdFailedToLoad)
{
isInterstitialOnAdFailedToLoad = false;
isInterstitialLoadingNow = false;
}
if (isOnAdFailedToLoad)
{
isOnAdFailedToLoad = false;
isInterstitialLoadingNow = false;
}
if (isRewardedOnAdClosed)
{
isRewardedOnAdClosed = false;
ButtonAdsUpdate();
RequestAndLoadRewardedAd();
}
if (isRewardedOnUserEarnedReward)
{
isRewardedOnUserEarnedReward = false;
SetTime();
ButtonAdsUpdate();
Analytics.AdsCoinsEnd();
CoinsManager.AdsVideoAddCoins();
}
if (isRewardedOnAdFailedToLoad)
{
isRewardedLoadingNow = false;
isRewardedOnAdFailedToLoad = false;
ButtonAdsUpdate();
}
if (isRewardedOnAdLoaded)
{
isRewardedLoadingNow = false;
isRewardedOnAdLoaded = false;
ButtonAdsUpdate();
}
}
void Destroy()
{
DestroyInterstitialAd();
DestroyRewardedAd();
}
private void HandleInitCompleteAction(InitializationStatus initstatus)
{
isHandleInitCompleteAction = true;
}
void OnApplicationPause(bool pauseStatus)
{
if (pauseStatus)
{
SetPauseEnable(true);
}
else
{
if (pauseStatus == isPause)
return;
SetPauseEnable(false);
ButtonAdsUpdate();
LoadAds();
}
}
void LoadAds()
{
if (isShowInterstitialAd && CoinsManager.isShowAds && (interstitialAd == null || !interstitialAd.IsLoaded()))
RequestAndLoadInterstitialAd();
if (rewardedAd == null || !rewardedAd.IsLoaded())
RequestAndLoadRewardedAd();
}
private AdRequest CreateAdRequest()
{
int npaValue = PlayerPrefs.GetInt("npa", 1); // "npa" = Non Personalized Ads
if (npaValue == 1)
return new AdRequest.Builder().AddExtra("npa", "1").Build();
else
return new AdRequest.Builder().Build();
}
#region INTERSTITIAL ADS
public void RequestAndLoadInterstitialAd()
{
if (!isShowInterstitialAd || !CoinsManager.isShowAds)
return;
try
{
if (isInterstitialLoadingNow)
return;
isInterstitialLoadingNow = true;
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "XXX";
#elif UNITY_IPHONE
string adUnitId = "";
#else
string adUnitId = "unexpected_platform";
#endif
DestroyInterstitialAd();
interstitialAd = new InterstitialAd(adUnitId);
// Add Event Handlers
interstitialAd.OnAdLoaded += InterstitialOnAdLoaded;
interstitialAd.OnAdFailedToLoad += InterstitialOnAdFailedToLoad;
interstitialAd.OnAdClosed += InterstitialOnAdClosed;
// Load an interstitial ad
interstitialAd.LoadAd(CreateAdRequest());
}
catch {}
}
public void DestroyInterstitialAd()
{
if (interstitialAd != null)
{
interstitialAd.OnAdLoaded -= InterstitialOnAdLoaded;
interstitialAd.OnAdFailedToLoad -= InterstitialOnAdFailedToLoad;
interstitialAd.OnAdClosed -= InterstitialOnAdClosed;
interstitialAd.Destroy();
}
}
public void ShowInterstitialAd()
{
if (!isShowInterstitialAd || !CoinsManager.isShowAds)
return;
try
{
if (interstitialAd != null && interstitialAd.IsLoaded())
interstitialAd.Show();
}
catch {}
}
public bool IsAdsLevelShow(int currentLevel)
{
return currentLevel > LevelsWithoutAdvertising && CoinsManager.isShowAds;
}
private void InterstitialOnAdClosed(object sender, EventArgs e)
{
isInterstitialOnAdClosed = true;
}
private void InterstitialOnAdLoaded(object sender, EventArgs e)
{
isInterstitialOnAdFailedToLoad = true;
}
private void InterstitialOnAdFailedToLoad(object sender, AdFailedToLoadEventArgs args)
{
isOnAdFailedToLoad = true;
}
#endregion
#region REWARDED ADS
public void RequestAndLoadRewardedAd()
{
try
{
if (isRewardedLoadingNow)
return;
isRewardedLoadingNow = true;
#if UNITY_EDITOR
string adUnitId = "unused";
#elif UNITY_ANDROID
string adUnitId = "XXX";
#elif UNITY_IPHONE
string adUnitId = "";
#else
string adUnitId = "unexpected_platform";
#endif
DestroyRewardedAd();
// create new rewarded ad instance
rewardedAd = new RewardedAd(adUnitId);
// Add Event Handlers
rewardedAd.OnAdLoaded += RewardedOnAdLoaded;
rewardedAd.OnAdFailedToLoad += RewardedOnAdFailedToLoad;
rewardedAd.OnAdClosed += RewardedOnAdClosed;
rewardedAd.OnUserEarnedReward += RewardedOnUserEarnedReward;
// Create empty ad request
rewardedAd.LoadAd(CreateAdRequest());
}
catch {}
}
public void DestroyRewardedAd()
{
if (rewardedAd != null)
{
rewardedAd.OnAdLoaded -= RewardedOnAdLoaded;
rewardedAd.OnAdFailedToLoad -= RewardedOnAdFailedToLoad;
rewardedAd.OnAdClosed -= RewardedOnAdClosed;
rewardedAd.OnUserEarnedReward -= RewardedOnUserEarnedReward;
}
}
public void ShowRewardedAd()
{
try
{
if (rewardedAd != null && rewardedAd.IsLoaded())
rewardedAd.Show();
}
catch {}
}
void SetPauseEnable(bool isEnable)
{
isPause = isEnable;
}
System.DateTime GetTime()
{
int lYear = PlayerPrefs.GetInt("GetAdsCoinsTimeYear", 2020);
int lMonth = PlayerPrefs.GetInt("GetAdsCoinsTimeMonth", 8);
int lDay = PlayerPrefs.GetInt("GetAdsCoinsTimeDay", 27);
int lHour = PlayerPrefs.GetInt("GetAdsCoinsTimeHour", 0);
int lMinute = PlayerPrefs.GetInt("GetAdsCoinsTimeMinute", 0);
int lSecond = PlayerPrefs.GetInt("GetAdsCoinsTimeSecond", 0);
System.DateTime lTime = new System.DateTime(lYear, lMonth, lDay, lHour, lMinute, lSecond);
return lTime;
}
void SetTime()
{
GetAdsCoinsTime = System.DateTime.Now;
if (!isAdsCoinsAvailableAlways)
GetAdsCoinsTime = GetAdsCoinsTime.AddHours(1);
PlayerPrefs.SetInt("GetAdsCoinsTimeYear", GetAdsCoinsTime.Year);
PlayerPrefs.SetInt("GetAdsCoinsTimeMonth", GetAdsCoinsTime.Month);
PlayerPrefs.SetInt("GetAdsCoinsTimeDay", GetAdsCoinsTime.Day);
PlayerPrefs.SetInt("GetAdsCoinsTimeHour", GetAdsCoinsTime.Hour);
PlayerPrefs.SetInt("GetAdsCoinsTimeMinute", GetAdsCoinsTime.Minute);
PlayerPrefs.SetInt("GetAdsCoinsTimeSecond", GetAdsCoinsTime.Second);
}
private void RewardedOnAdClosed(object sender, EventArgs e)
{
isRewardedOnAdClosed = true;
}
private void RewardedOnUserEarnedReward(object sender, Reward args)
{
isRewardedOnUserEarnedReward = true;
}
private void RewardedOnAdFailedToLoad(object sender, AdErrorEventArgs args)
{
isRewardedOnAdFailedToLoad = true;
}
private void RewardedOnAdLoaded(object sender, EventArgs e)
{
isRewardedOnAdLoaded = true;
}
public void ButtonAdsUpdate()
{
if (isTimeOK())
{
if (rewardedAd != null && rewardedAd.IsLoaded())
{
ButtonBuyFreeImage.enabled = true;
ButtonBuyFreeTextTime.enabled = false;
ButtonBuyFreeText.enabled = false;
ButtonBuyFree.enabled = true;
}
else
{
ButtonBuyFreeImage.enabled = false;
ButtonBuyFreeTextTime.enabled = false;
ButtonBuyFreeText.enabled = true;
ButtonBuyFree.enabled = false;
}
}
else
{
if (!isTimerEnable)
{
isTimerEnable = true;
StartCoroutine(TimerUpdate());
}
}
}
public IEnumerator TimerUpdate()
{
ButtonBuyFreeImage.enabled = false;
ButtonBuyFreeTextTime.enabled = true;
ButtonBuyFreeText.enabled = false;
ButtonBuyFree.enabled = false;
System.TimeSpan timeSpan = GetAdsCoinsTime.Subtract(System.DateTime.Now);
ButtonBuyFreeTextTime.text = String.Format("{0:00}:{1:00}", timeSpan.Minutes, timeSpan.Seconds);
while (!isPause && window.activeInHierarchy)
{
if (isTimeOK())
{
if (rewardedAd != null && rewardedAd.IsLoaded())
{
ButtonBuyFreeImage.enabled = true;
ButtonBuyFreeTextTime.enabled = false;
ButtonBuyFreeText.enabled = false;
ButtonBuyFree.enabled = true;
}
else
{
ButtonBuyFreeImage.enabled = false;
ButtonBuyFreeTextTime.enabled = false;
ButtonBuyFreeText.enabled = true;
ButtonBuyFree.enabled = false;
}
break;
}
else
{
timeSpan = GetAdsCoinsTime.Subtract(System.DateTime.Now);
ButtonBuyFreeTextTime.text = String.Format("{0:00}:{1:00}", timeSpan.Minutes, timeSpan.Seconds);
yield return new WaitForSeconds(1.0f);
}
}
isTimerEnable = false;
}
private bool isTimeOK()
{
if (isAdsCoinsAvailableAlways)
return true;
else
return GetAdsCoinsTime < System.DateTime.Now;
}
#endregion
}