Unity Ads Plugins

Hello, I am new to Solar2D development
I am quite confused. I am recently try to add an advertisement from unity in my developed game app

however, it has no response, the game loaded normally but the ads does not appear
I am not sure whether it is my code problem or it is just my misunderstanding

I just follow the documentation

The ads did not show up no matter in Corona Simulator or I built for android phone

After viewing the others post in Solar2D Community, some post said Unity Plugins need to be paid before you use.

Can anyone guide me through these matter? I am quite lost. thank you.

Hi!

Someone more familiar with Unity Ads will step in but before they do, here are my two cents:

  • I haven’t seen it mentioned in docs but most of the time, ad plugins are not supported on the Simulator. For your Android build, it may require you to build with a release key instead of debug keystore. Please check which one you are using. Here is the documentation page for Signing and Building for Android.
  • If you are using a release key and it’s still not showing, I can see two warnings on that page. You may want to check those out.
    This:

If you are building for Android, you should remove any legacy inclusion of the ["plugin.google.play.services"] plugin from your build.settings.

… and that:

Also, minimum Android API level required is 19.

Please make sure you check those while someone else steps in. Hope it works!

The plugin is free, like all first party Solar2D plugins.

Like bgmadclown already said, the ads plugins don’t work on the simulator. The issue is either in your code and/or Unity’s side.

Make sure that your build.settings are correct, you have a valid app id from Unity Ads, and you init the plugin correctly before trying to load ads. Also, make sure you load ads before you try to show them.

Thank you for your replies.
I have tried to use a release key instead of debug keystore.
however, my phone warned me that i am not registered for google play (Anyway i skipped it and continue to install)

Then when i open my app, the ads is still not showing. Do you have any idea.
I also attached my code. see if it has any problem.

local function adListener( event )
    if ( event.phase == "init" ) then  -- Successful initialization
        print( event.provider )
    unityads.load("Banner_Android")
    end
end

function scene:create( event )

	local sceneGroup = self.view
        mainGroup = display.newGroup()
        .....skipped code
            unityads.init( adListener, { gameId="XXXXXXXX" } )
    if (unityads.isLoaded("Banner_Android")) then
        unityads.show("Banner_Android")
    end


end


	--
	-- Android section
	--
	android =
	{
        minSdkVersion = "19",
		usesPermissions =
		{
			"android.permission.INTERNET",
		},
	},

	--
	-- iOS section
	--
	iphone =
	{
		xcassets = "Images.xcassets",
		plist =
		{
			UIStatusBarHidden = false,
			UILaunchStoryboardName = "LaunchScreen",
			NSUserTrackingUsageDescription = "Your data will be used to provide you a better and personalized ad experience.",
            SKAdNetworkItems = {
                { SKAdNetworkIdentifier = "4dzt52r2t5.skadnetwork" },
                { SKAdNetworkIdentifier = "bvpn9ufa9b.skadnetwork" },
            },
		},
	},

	--
	-- Plugins section
	--
    plugins =
    {
        ["plugin.unityads.v4"] =
        {
            publisherId = "com.solar2d"
        },
    },

Looking at your code I suspect you are initializing the plugin way too late for it to load an ad. Since this is a network related event there is a high possibility that you are not giving the plugin enough time to request and load an ad. Can you try initializing the plugin in main.lua and start calling for ads some time later?

I’m assuming you already configured the placement IDs in dashboard as instructed here:

I tried to put the code in main.lua. but the same.

-----------------------------------------------------------------------------------------
--
-- main.lua
--
-----------------------------------------------------------------------------------------

-- Your code here

local composer = require("composer")
display.setStatusBar(display.HiddenStatusBar)
local unityads = require("plugin.unityads.v4")

local function adListener( event )
    if ( event.phase == "init" ) then  -- Successful initialization
        print( event.provider )
    unityads.load("Banner_Android")
    end
end
unityads.init( adListener, { gameId="XXXXXXX" } )

composer.gotoScene("menu")

I just registered my Unity Account. and the placement / ads are the default. There are not much to configure. Am I correct?

The plugin doesn’t support banner ads. It only works with interstitial video or rewarded video.

Also, remember that init is an asynchronous function. The code doesn’t wait for the initialisation to finish before moving on. Usually, when testing ads, it’s good practice to put the load/show ad behind some button that you can repeatedly press to better test the ad.

Also, while developing, make sure to include the testMode parameter in the init call.

Succeed!!! :smiley: :smiley: :smiley: :smiley:
love you brother

The final problem is i do not have enough time to load the ads

Basically, you can set a timer to check if you can show ads at that time. Something like the piece below. Keep in mind that I haven’t tried it so proceed with caution and replace it with your own :slight_smile:

local function showUnityAds()
   if (unityads.isLoaded("Banner_Android")) then
        unityads.show("Banner_Android")
   else
        -- Check if you can show ads after 1000ms
        timer.performWithDelay(1000, showUnityAds, 1)
   end
end