Unity mediation adapter fails to initialize.

401 views
Skip to first unread message

stevieh...@gmail.com

unread,
Aug 28, 2024, 10:42:14 AM8/28/24
to Google Mobile Ads SDK Developers
Hi,

I've recently added Unity ads to our admob mediation list for our app. The ad inspector is showing it as "Didn't initialize" (see screenshot). Any ideas why?

1.All the ad units/placements are correct in unity/admob dashboards.
2.Unity ads mediator and sdk are being included in build.gradle:

    implementation("com.unity3d.ads:unity-ads:4.12.1")
    implementation("com.google.ads.mediation:unity:4.12.2.0")

3.It appears the SDK is being initialized from admob correctly at startup (from logcat):

UnityAds                com.blah.dev.myapp             D  com.unity3d.services.core.misc.Utilities.writeFile() (line:80) :: Wrote file: /data/user/0/com.rubicon.dev.mahjongg/files/UnityAdsStorage-public-data.json
UnityAds                com.blah.dev.myapp             D  com.unity3d.services.core.device.Storage.sendEvent() (line:89) :: Couldn't send storage event to WebApp
UnityAds                com.blah.dev.myapp             D  com.unity3d.services.ads.UnityAdsImplementation.initialize() (line:1) :: ENTERED METHOD
UnityAds                com.blah.dev.myapp             D  com.unity3d.services.UnityServices.initialize() (line:1) :: ENTERED METHOD
UnityAds                com.blah.dev.myapp             I  com.unity3d.services.UnityServices.initialize() (line:475) :: Initializing Unity Services 4.12.1 (41201) with game id 123456(redacted) in production mode, session 1234(redacted)
UnityAds                com.blah.dev.myapp             I  com.unity3d.services.UnityServices.initialize() (line:519) :: Unity Services environment check OK

4. Clicking on "troubleshoot" revealse this confusing statement:

"Each third-party ad source SDK adapter needs to be explicitly initialized in your codebase with the necessary parameters."

No it doesn't. I've been using mediation with Chartboost, Facebook and AppLovin for years. All those mediators are automatically initialised by the Admob Mobile Ads SDK.

As specified by the Admob "Getting started documentation":

"The quick start guide shows you how to initialize the Mobile Ads SDK. DURING THAT INITIALIZATION CALL, MEDIATION ADAPTERS ALSO GET INITIALIZED."

There's a lot wrong here (documentation wise). More importantly, I'd like to know why the init fails. There's no proguard exceptions for this, so I'm assuming
they're not required.

Many thanks,

Steve.
Screenshot_20240828_152216.png

Mobile Ads SDK Forum Advisor

unread,
Aug 28, 2024, 4:27:35 PM8/28/24
to stevieh...@gmail.com, google-adm...@googlegroups.com
Hi,

For us to further investigate this kindly provide us below details via "Reply to author" option:
  • Mobile Ads SDK version
  • Unity editor version
Once provided we will be running google sample project and try to replicate the issue and provide further assistance.
 
This message is in relation to case "ref:!00D1U01174p.!5004Q02vFTzD:ref" (ADR-00265400)

Thanks,
 
Google Logo Mobile Ads SDK Team

 

stevieh...@gmail.com

unread,
Aug 28, 2024, 6:45:02 PM8/28/24
to Google Mobile Ads SDK Developers
The problem is minification.

There are no proguard rules that stop the minification of the Unity Mediation adapter, therefore Admob is unable to find the initialize() method.

Proguard lines I have tried and do not work:

-keep public class com.google.android.gms.** { public protected *; }
-keep class com.google.ads.** { *; }
-keep class com.google.ads.mediation.unity.UnityMediationAdapter { *; }
-keep class com.google.ads.mediation.unity.UnityMediationAdapter { void initialize(android.content.Context,com.google.android.gms.ads.mediation.InitializationCompleteCallback,java.util.List); }


I'd appreciate if you could ask your engineers for the correct proguard line to protect the adaapter class from minifciation. Minification is a must, not a option for us and many developers.

Many thanks,

Steve.

Mobile Ads SDK Forum Advisor

unread,
Aug 29, 2024, 3:51:03 AM8/29/24
to stevieh...@gmail.com, google-adm...@googlegroups.com

Hi Steve,

Thank you for contacting the Mobile Ads SDK support team. 

This Unity publishing option lets you enable java code minification. If you enable minification you will also need to create a custom proguard file to keep classes referenced by the SDK.

  1. Enable Custom Proguard File
    Go to Project Settings > Player > Android > Publishing Settings > Build, and select:
    • Custom Proguard File
  2. Open /Assets/Plugins/Android/proguard-user.txt and add the following:
    • -keep class com.google.** { public *; }

Please reach out to us, if you need any further assistance.  

stevieh...@gmail.com

unread,
Aug 29, 2024, 8:49:20 AM8/29/24
to Google Mobile Ads SDK Developers
Hi,

This is not a Unity app, it's a standard JNI app, so I'm specifying proguard rules in proguard-rules.pro.

Adding  -keep class com.google.** { public *; } does not work and would also lead to too many classes not being minified.

The correct solution is:

-keep class gatewayprotocol.** { *; }
-keep class com.google.protobuf.* { *; }

This will allow Unity ads to function correctly when minified. You may consider adding this to your online documentation, as it stands it won't work.

Thanks,

Steve.
Reply all
Reply to author
Forward
0 new messages