DefVideoAds (plugin for Unity ADS). Video ADS native extension

According to the call stack you posted it’s not related to the extension at all.

1 Like

Usually dev tries to load ads a bit in advance to reduce waiting time and improve user expirience when he interacts with ADS. Better UX in this case means user who don’t think twice to watch or not to watch.

For example if you know that in popup you have an option to watch ADS, you load ADS on popup creation.
If you have active gameplay and wanna be sure game will not lagg when you will be loading ads for the next interstitiall - you do it right after the prev one (depends on frequency ofc).

Indeed, it would’ve been inappropriate for me to (for example) create an issue at Issues · AGulev/DefVideoAds · GitHub
But there is some ‘interaction’ between the engine and the ad playback that causes this, even if the likely fix is in the engine.

Are you sure you added DefUnityAds and nothing else? engine version update? Render_script update? Spine plugin update?

I think it would be better to open a ticket here

If it’s somehow related to the extension, then it’s related to the most of the extensions that works this way.

OK I’ll open an engine ticket.
We have a build that has a ‘simulate ad’ debug option that we can enable through imgui.
When enabled, it skips calls to unityads.load() and unityads.show(), and the game code that reacts to unityads.MSG_SHOW / unityads.EVENT_COMPLETED is called immediately.

The results are:
On LG K8 2017 device:
Simulate ADS OFF - 7/12 crashes
Simulate ADS ON - 0/12 crashes

On Huawei P Smart 2021 device:
Simulate ADS OFF - 0/22 crashes
Simulate ADS ON - 0/22 crashes

Samsung Galaxy A03
Simulate ADS OFF - 0/22 crashes
Simulate ADS ON - 0/22 crashes

Maybe it’s related to focus lost event, and some values that can’t be 0 become 0.
For example these changes in the default render_scriptprevent such an issue.

But maybe it’s also happening in some cases inside the engine itself (not in render script, but internal systems). We need to take a look, that’s why I’m asking you to create a ticket. Thank you.

1 Like

Unity ADS SDK updated to 4.4.0

  • Updated Unity ADS SDK to 4.4.0 (iOS / Android)
  • Update info.plist with the newest SKAdNetworkIdentifier
  • New error type unityads.ERROR_TIMEOUT for unityads.MSG_SHOW added
9 Likes

Has anyone successfully deployed 4.4.0 on Android? I’m trying it, but getting an exception on the Unity Ads service initialization.

09-22 21:57:12.309 31492 31540 E UnityAds: com.unity3d.services.core.cache.CacheDirectory.getCacheDirectory() (line:38) :: Creating external cache directory failed: Attempt to invoke virtual method 'java.io.File android.content.Context.getExternalCacheDir()' on a null object reference
09-22 21:57:12.310 31492 31540 W System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'java.io.File android.content.Context.getFilesDir()' on a null object reference
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.cache.CacheDirectory.getCacheDirectory(CacheDirectory.java:54)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.properties.SdkProperties.getCacheDirectory(SdkProperties.java:198)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.properties.SdkProperties.getCacheDirectory(SdkProperties.java:190)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.properties.SdkProperties.getLocalConfigurationFilepath(SdkProperties.java:174)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.configuration.ConfigurationReader.getLocalConfiguration(ConfigurationReader.java:34)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.core.configuration.ConfigurationReader.getCurrentConfiguration(ConfigurationReader.java:21)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.ads.operation.load.LoadModuleDecoratorTimeout.<init>(LoadModuleDecoratorTimeout.java:25)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.ads.operation.load.LoadModule.getInstance(LoadModule.java:35)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.services.ads.UnityAdsImplementation.load(UnityAdsImplementation.java:171)
09-22 21:57:12.310 31492 31540 W System.err:    at com.unity3d.ads.UnityAds.load(UnityAds.java:281)
09-22 21:57:12.310 31492 31540 W System.err:    at com.agulev.defunityads.DefUnityAdsJNI.load(DefUnityAdsJNI.java:235)
09-22 21:57:12.311 31492 31540 D UnityAds: com.unity3d.services.ads.UnityAdsImplementation.initialize() (line:63) :: ENTERED METHOD
09-22 21:57:12.311 31492 31540 D UnityAds: com.unity3d.services.UnityServices.initialize() (line:35) :: ENTERED METHOD
09-22 21:57:12.311 31492 31540 I UnityAds: com.unity3d.services.UnityServices.initialize() (line:119) :: Initializing Unity Services 4.4.0 (4400) with game id 3530625 in production mode
09-22 21:57:12.311 31492 31540 E UnityAds: com.unity3d.services.core.configuration.EnvironmentCheck.testCacheDirectory() (line:49) :: Unity Ads cache directory check fail: no working cache directory available
09-22 21:57:12.311 31492 31540 E UnityAds: com.unity3d.services.UnityServices.initialize() (line:133) :: Error during Unity Services environment check, halting Unity Services init

I don’t think it could be this extension’s fault? I tried to Google the error but didn’t see anything. :man_shrugging:

The message is implying there is a null reference where a Context is expected. Maybe related to this line in the extension?

Update: I reverted to 4.2.1, and now initialization and loading/showing ads work.

However, after a Rewarded Ad is completed, the whole app crashes. I’ve attached the adb logs around when it happens. Unfortunately I can’t isolate which update (this extension or defold) is causing it. Learned my lesson here, update one thing at a time!
reward_ad_finished_crash.txt (19.9 KB)

1 Like

Strange, I test every new release on a couple of mobile devices and I actively use 4.2.1 in released games.

Could you pls open two separate tickets in the extension project. One for 4.4.0 and another one for 4.2.1, add more info about phone you test on and its os version.

Thank you.

1 Like

I’ve created the 2 issues. Happy to share some of the project code with you also, just ask on the Github issues if needed.

Hopefully I’m “holding it wrong” or it’s an easy fix!

1 Like

Thank you, I’ll take a look

Unity ADS SDK updated to 4.4.1

  • Updated Unity ADS SDK to 4.4.1 (iOS / Android)
  • Update info.plist with the newest SKAdNetworkIdentifier
7 Likes

As I port my game to iOS, and learn more about their rules for privacy, I have questions about the request_idfa() method.

What is the recommended way to initialize Unity Ads on iOS?

On Android, I just call the initialize method right away.

On iOS, should I call request_idfa first, and then in the callback handler, call initialize after the IDFA message is received?

Or is it okay to call the IDFA then inititialize methods back to back? I assume both are async, so perhaps it’s better to wait for the callback?

EDIT: On second thought… if you don’t call initialize, you can’t use the callback, so it seems like this is the right answer? Does the IDFA thing simply tell the SDK it should show a dialog during init?

unityads.request_idfa()
unityads.initialize(......)
3 Likes

Hey,

There is unityads.set_callback(unity_ads_callback) function in the extension. Using it you can set callback without initialization.

Apple requires to make this request BEFORE ANY interaction that may use IDFA. So, If you will try to initialize ads before IDFA requests, more likely you will not pass the Apple’s review.

I do it before initialization. It depends on the game. Sometimes I initialize ADS before showing it (because it opens later the progress of the game) sometimes in the very beginning after the first start.

I saw recommendations to show an in-game explanation pop-up for what you need IDFA before request which may help to increase the number of people who approve it. But I’ve never tried it myself.

2 Likes

Thanks for pointing out the set_callback method. I assume it’s okay to call initialize from within the callback.

Something like this (greatly simplified example)?

function unity_ads_callback(...)
	if message_id == unityads.MSG_IDFA then
		unityads.initialize(UNITY_GAME_ID_IOS, unity_ads_callback, false)
	elseif message_id == unityads.MSG_INIT then
		if message.event == unityads.EVENT_COMPLETED then
			M.load_banner()
			M.load_rewarded()
		end
	end
end


function init()
	if globals.IS_IOS then -- sys.get_sys_info().system_name == "iPhone OS"
		unityads.set_callback(unity_ads_callback)
		unityads.request_idfa()
	else
		unityads.initialize(UNITY_GAME_ID_ANDROID, unity_ads_callback, false) 
	end
end
1 Like

yes, it looks like something I usually use on ios

1 Like

Seems like is not merging the manifests.

Could you please explain what do you mean?

I keep being amazed by the ease of setup and use of extension in Defold. .

3 Likes

Apologies from a newbie who doesn’t know how to access android crash data.
With the last update to the plugin I thought I was doing something wrong as my android device was crashing as soon as I loaded a banner ad, but as a last try I installed version 4.9.2 of the plugin and it worked fine.
If you can point me in the correct direction, I could try to get some crash debug info

1 Like