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.
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.
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
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
I also have problems showing ads (testads). I can get into the INIT phase, then loading rewarded unity ad. But I can not show it, check if it has loaded.
Could you please show a sample of your working code maybe with the delay you have included. Everything I have tried does not seem to have any impact
I tried this also, but with Version 2024.3706 (2024.3.17) and actual XCode it doesn’t work.
I can get into INIT in the unityads listener BUT after this NOTHING! Can not load or show any ads, even with correct Unity dashboard settings and all. I really tried anything here.
Any help welcome! Even if someone can confirm the Unity ads (especially rewarded ads!) can be shown with this build, loaded etc.
local unityads = require("plugin.unityads.v4")
.......
function scene:create( event )
gameState= true
unityads.load("Interstitial_Android")
local sceneGroup = self.view
gameover.lua
local unityads = require("plugin.unityads.v4")
local function showads()
if (unityads.isLoaded("Interstitial_Android")) then
unityads.show("Interstitial_Android")
else
unityads.load("Interstitial_Android")
end
end
local function gotoMenu()
showads()
composer.gotoScene( "menu", { time=800, effect="crossFade" } )
end
function scene:create( event )
......
menuButton:addEventListener("tap", gotoMenu)
end
Are you also using it on iOS?
If so, how is your build.settings looking? Is there a difference to the Solar2D document versions?
(Btw: I already have updated all the server info list stuff to the list Unity was suggesting to add in plist)
Argh… I did find something, but am not sure if it was the problem (and can not test it right now):
I had a .lua file after main in which I have used _G.unityads and had this used like this:
_G.unityads = {}
This way I had stopped unityads to work some months ago. I also made a list like this for all calls:
_G.unityads.init=function() end
_G.unityads.load=function() end
…
NOW the big question is:
I have added unityads and a listener in main.lua… WITHOUT using _G.unityads, just unityads this time. Is it possible THIS can interfere with each other? That would explain my problems.
Is a variable with “_G.variable” completely different to “variable”???