androidunity-game-engineunityads

Unity Ads cannot show ads: webapp not initialized


I downloaded the latest Unity Ads SDK and followed the instructions to integrate it on my android app.

UnityAds.init(this, "xxxxxxx", null);

The initialization was successful and the log shows that the ad was downloaded.

Initializing Unity Ads version 1508 with gameId xxxxxxx

Requesting Unity Ads ad plan from https://xxxxxxx

Unity Ads initialized with 3 campaigns and 2 zones

Unity Ads cache: File /storage/xxxxxxx/yyyyyyy.mp4 of 1445875 bytes downloaded in 9102ms

I try to show the ad:

if (UnityAds.canShow()) {
    UnityAds.show();
}

Then this error message appears:

Unity Ads cannot show ads: webapp not initialized

What am I missing?


Solution

  • The error is that the IUnityAdsListener (third initialization parameter) is required and cannot be null.

    The fix is to add the listener to the init method like below:

    UnityAds.init(this, "xxxxxxx", new IUnityAdsListener() {
        @Override
        public void onHide() {
        }
    
        @Override
        public void onShow() {
        }
    
        @Override
        public void onVideoStarted() {
        }
    
        @Override
        public void onVideoCompleted(String s, boolean b) {
        }
    
        @Override
        public void onFetchCompleted() {
        }
    
        @Override
        public void onFetchFailed() {
        }
    });