- Home /
Android app keeps quiting after adding Unity ads
Hi, recently I started adding ads to my project. It is an Android app. In editor everything works fine, however when I built an .apk file to test it on my phone, app quits after few seconds from loading a scene. This is before any ad is being called. I narrowed it down to being sure that problem starts while I have this script (below)active on game object. I use unity 2018.3.02f personal. At the beginning I thought it might be caused by not signed app, however after adding key it keeps stopping, it doesn't matter either if ads are initialized in testMode=true or false.
Here is script I use on AdManager GameObject:
using UnityEngine;
using UnityEngine.Monetization;
public class AdManager : MonoBehaviour
{
public static AdManager instance = null;
private string appId = "-----";
private string rewardedVideo = "rewardedVideo";
private string normalVideo = "video";
void Awake()
{
if(instance != null)
{
Destroy(gameObject);
}
else
{
instance = this;
DontDestroyOnLoad(gameObject);
}
}
void Start()
{
Monetization.Initialize(appId, false);
}
public void PlayAd(string video, ShowAdFinishCallback callback)
{
if(Monetization.IsReady(video))
{
ShowAdPlacementContent sad = null;
sad = Monetization.GetPlacementContent(video) as ShowAdPlacementContent;
if(sad != null)
{
sad.Show(callback);
}
}
}
public void PlaySimpleAd(ShowAdFinishCallback callback)
{
PlayAd(normalVideo, callback);
}
public void PlayRewardedAd(ShowAdFinishCallback callback)
{
PlayAd(rewardedVideo, callback);
}
}
Your answer
Follow this Question
Related Questions
Gradle build faild. see... error "in unity 2020.1.4f1!!!" 0 Answers
Android Builds ends up with error 2 Answers
MissingMethodException: get_vuforiaEnabled() 3 Answers
Failed to start several times restore it by clearing history 1 Answer
APK is installed but does not show the application and does not open either. 1 Answer