Unity Admob googleMobileAdsClientFactory Null Reference

1,674 views
Skip to first unread message

Hyunsik Lee

unread,
Oct 27, 2017, 10:58:27 PM10/27/17
to Google Mobile Ads SDK Developers
Hello, 

I'm having an issue in unity with the unity plugin. Anytime i try to run the following lines:

rewardBasedVideoAd = RewardBasedVideoAd.Instance;

or 

MobileAds.Initialize(appid);


This portion always throws a null reference error.
Type googleMobileAdsClientFactory = Type.GetType(
                "GoogleMobileAds.GoogleMobileAdsClientFactory,Assembly-CSharp");

Throwing the following error:
NullReferenceException: Object reference not set to an instance of an object
GoogleMobileAds.Api.RewardBasedVideoAd..ctor () (at Assets/Plugins/GoogleMobileAds/Api/RewardBasedVideoAd.cs:40)
GoogleMobileAds.Api.RewardBasedVideoAd..cctor () (at Assets/Plugins/GoogleMobileAds/Api/RewardBasedVideoAd.cs:25)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for GoogleMobileAds.Api.RewardBasedVideoAd
AdvertisementTest.Start () (at Assets/Plugins/AdvertisementTest.cs:25)


Is there any reason this might be happening? I'm not sure where to begin looking, and i've searched everywhere and couldn't find a solution. I have plugin v3.8.0 running on Unity 2017.1.1p4

Joshua Lagonera (Mobile Ads SDK Team)

unread,
Oct 30, 2017, 12:25:28 AM10/30/17
to Google Mobile Ads SDK Developers
Hi there,

Can you try doing a re-import of the official Unity Plugin and see if you can still replicate the issue? Can you also check if you are able to reproduce the error on our sample setup? If possible, may we also request a sample project from you where we can see the issue so we may be able to investigate further?

Regards,
Joshua Lagonera
Mobile Ads SDK Team

Joshua Lagonera (Mobile Ads SDK Team)

unread,
Nov 8, 2017, 6:37:15 AM11/8/17
to Google Mobile Ads SDK Developers
Hi there,

Hope you are doing well.

Are you still receiving a NullReferenceException? Please let us know if you would still need our assistance and provide to us the previously requested information if you still do.

Regards,
Joshua Lagonera
Mobile Ads SDK Team

On Saturday, October 28, 2017 at 10:58:27 AM UTC+8, Hyunsik Lee wrote:

Andres Klagges

unread,
Dec 4, 2017, 2:03:46 PM12/4/17
to Google Mobile Ads SDK Developers
Hi, i was having the same issue everywhere reflexion was used. I figure it out that removing the assembly fixed the problem and the plugin seemed to work. 

Basically leaving the script like: "Type googleMobileAdsClientFactory = Type.GetType( "GoogleMobileAds.GoogleMobileAdsClientFactory");"

Is this ok? 

I'm using unity 2017 2.0f3

Ivan Bautista (Mobile Ads SDK Team)

unread,
Dec 5, 2017, 2:17:12 AM12/5/17
to Google Mobile Ads SDK Developers
Hi Andres,

Since your question is more about general code implementation for Unity or C# rather than anything specific to the code implementation of the Google Mobile Ads Unity plugin, it would be best that you have this confirmed by the experts over at Unity developer forums or StackOverflow. 

On the other hand, feel free to get back to us and create a new thread if you have any further technical concerns specific to the implementation of the Google Mobile Ads Unity plugin and we will be happy to assist you.

Regards,
Ivan Bautista
Mobile Ads SDK Team

Nikita Kostyuk

unread,
Feb 16, 2018, 1:37:23 PM2/16/18
to Google Mobile Ads SDK Developers
Hi there, I have the same issue as Hyunsik Lee has. The re-importing of official Unity Plugin doesn't help me. Also the demo-scene in plugin dont work at my devise(nexus 5x with the android 8.1). What I should doing to resolve the problem?

понедельник, 30 октября 2017 г., 7:25:28 UTC+3 пользователь Joshua Lagonera (Mobile Ads SDK Team) написал:

mobileadssdk-a...@google.com

unread,
Feb 16, 2018, 4:10:12 PM2/16/18
to Nikita Kostyuk, Google Mobile Ads SDK Developers
Hi Nikita,

Thanks for reaching out to us. It looks like an integration issue. Can you try to reproduce with our sample script? Or see what you might be missing within your implementation? If you are still unable to find a fix, do share your sample app with us and we will have a look.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.
To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-admob-ads-sdk/468ac496-e115-49b2-9afd-e6904cf12279%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

KoS Games

unread,
Feb 16, 2018, 5:04:59 PM2/16/18
to mobileadssdk-a...@google.com, Google Mobile Ads SDK Developers
I tried this sample("HelloWorld") but problem the same. At start game when initialize the SDK (MobileAds.Initialize(appId)) and get singleton revarded based video ad reference ( rewardedBasedVideo = rewardedBasedVideo Ad.Instance) I catch error. And after, when I touch to button wich show ad, I noticed that rewardedBasedVideo object equals null.

I doesn't know what now happend, about 3-4 month later in test project I integrate admob and it was working fine but at this project I have a lot of problems with this plugin


сб, 17 февр. 2018 г., 0:09 <mobileadssdk-a...@google.com>:
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads...@googlegroups.com.

To post to this group, send email to google-adm...@googlegroups.com.

mobileadssdk-a...@google.com

unread,
Feb 19, 2018, 3:03:26 PM2/19/18
to KoS Games, Google Mobile Ads SDK Developers
Hi there,

Thanks for getting back to us. Can you share your sample project with your implementation for us to investigate further?

Please use "Reply privately to Author" option to share the requested information.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 02/16/18 17:04:31 kosga...@gmail.com wrote:
I tried this sample("HelloWorld") but problem the same. At start game when initialize the SDK (MobileAds.Initialize(appId)) and get singleton revarded based video ad reference ( rewardedBasedVideo = rewardedBasedVideo Ad.Instance) I catch error. And after, when I touch to button wich show ad, I noticed that rewardedBasedVideo object equals null.

I doesn't know what now happend, about 3-4 month later in test project I integrate admob and it was working fine but at this project I have a lot of problems with this plugin


сб, 17 февр. 2018 г., 0:09 <mobileadssdk-advisor+support@google.com>:
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

To post to this group, send email to google-admob-ads-sdk@googlegroups.com.

mobileadssdk-a...@google.com

unread,
Feb 21, 2018, 5:05:20 PM2/21/18
to KoS Games, Google Mobile Ads SDK Developers
Hi Nikita,

Thanks for providing the sample. Can you call this.rewardBasedVideo = RewardBasedVideoAd.Instance and  RequestRewardedVideo() from the same callback? Instead of calling one from Awake() and other from Start(), make sure they are called from the same callback and try again. I suspect that this.rewardBasedVideo = RewardBasedVideoAd.Instance; is not being initialized before the AdRequest is being made. Let us know if this fixes the issue.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsubscrib...@googlegroups.com.

mobileadssdk-a...@google.com

unread,
Feb 22, 2018, 3:04:51 PM2/22/18
to KoS Games, Google Mobile Ads SDK Developers
Hi Nikita,

This is working with this modified sample app. Can you confirm the same on your end? You can also find implementation steps with our guidelines.  Let us know if that helps. 

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 02/21/18 17:04:56 mobileadssdk-a...@google.com wrote:
Hi Nikita,

Thanks for providing the sample. Can you call this.rewardBasedVideo = RewardBasedVideoAd.Instance and  RequestRewardedVideo() from the same callback? Instead of calling one from Awake() and other from Start(), make sure they are called from the same callback and try again. I suspect that this.rewardBasedVideo = RewardBasedVideoAd.Instance; is not being initialized before the AdRequest is being made. Let us know if this fixes the issue.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

mobileadssdk-a...@google.com

unread,
Feb 26, 2018, 3:01:54 PM2/26/18
to KoS Games, Google Mobile Ads SDK Developers
Hi Nikita,

Let me repost your private message and you can find my answers to your issue here :

Hmm... It works perfect, the application doesn't crash at launch, BUT in this modified sample app when I try to add button which on click will show the ad I has error at the building application 

CommandInvokationFailure: Unable to merge android manifests. See the Console for more details. 
C:/Program Files/Java/jdk1.8.0_131\bin\java.exe -Xmx2048M -Dcom.android.sdkmanager.toolsdir="C:/Program Files (x86)/Android/android-sdk\tools" -Dfile.encoding=UTF8 -jar "D:\_programs\Unity\Editor\Data\PlaybackEngines\AndroidPlayer/Tools\sdktools.jar" -

stderr[

]
stdout[
Warning: [Temp\StagingArea\AndroidManifest-main.xml:12, D:\$Desctope\MAD 3.1.1 Reward\MAD 3.1.1\Temp\StagingArea\android-libraries\adcolony-3.3.0.1\AndroidManifest.xml:3] Main manifest has <uses-sdk android:targetSdkVersion='25'> but library uses targetSdkVersion='26'
Warning: [Temp\StagingArea\AndroidManifest-main.xml:12, D:\$Desctope\MAD 3.1.1 Reward\MAD 3.1.1\Temp\StagingArea\android-libraries\com.google.ads.mediation.applovin-7.7.0.0\AndroidManifest.xml:3] Main manifest has <uses-sdk android:targetSdkVersion='25'> but library uses targetSdkVersion='26'
Warning: [Temp\StagingArea\AndroidManifest-main.xml:12, D:\$Desctope\MAD 3.1.1 Reward\MAD 3.1.1\Temp\StagingArea\android-libraries\com.google.ads.mediation.unity-2.1.2.0\AndroidManifest.xml:3] Main manifest has <uses-sdk android:targetSdkVersion='25'> but library uses targetSdkVersion='26'
]
exit code: 1
UnityEditor.Android.Command.Run (System.Diagnostics.ProcessStartInfo psi, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandInternal (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.Android.AndroidSDKTools.RunCommandSafe (System.String javaExe, System.String sdkToolsDir, System.String[] sdkToolCommand, Int32 memoryMB, System.String workingdir, UnityEditor.Android.WaitingForProcessToExit waitingForProcessToExit, System.String errorMsg)
UnityEditor.HostView:OnGUI()
Unity, Applovin and AdColony has targetSDKVersion as 25 and one of the libraries or your project is having it at 26. There is a mismatch and the manifest files are not merging to make a build. You need to look into your project build settings to resolve this issue.

And I also doesn't understand, what the plugins or librarays you add to project. The standart admob plugin doesn't contain APPLOVIN, ADCOLONY librarys. Why admob plugin doesn't work whithout APPLOVIN, ADCOLONY librarys?

It does work. The sample app provided also shows integration with Applovin, UnityAd and AdColony. You can remove those if you are only mediating with AdMob network.

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 02/22/18 15:04:29 mobileadssdk-a...@google.com wrote:
Hi Nikita,

This is working with this modified sample app. Can you confirm the same on your end? You can also find implementation steps with our guidelines.  Let us know if that helps. 

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

mobileadssdk-a...@google.com

unread,
Feb 28, 2018, 3:46:50 PM2/28/18
to KoS Games, Google Mobile Ads SDK Developers
Hi Nikita,

Thanks for getting back to us. For better tracking purposes, please continue the discussion on forum and use the "Reply Privately to Author" option only when sending sensitive information.

Regarding the issue with the project that you have shared, I'm unable to open the project for some reason. I don't notice any particular issue with your implementation and was wondering whether you are still noticing the same issue? Can you send us the device logs again?


Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Harsh Mehta

unread,
Apr 12, 2019, 7:15:31 AM4/12/19
to google-adm...@googlegroups.com
Hi Nikita,

I have also been facing this issue.

I get an exception at MobileAds.Initialize(appId) itself.

I have tried the Sample code mentioned above and get the same issue.

NullReferenceException: Object reference not set to an instance of an object
at GoogleMobileAds.Api.MobileAds.GetMobileAdsClient () [0x00016] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0
at GoogleMobileAds.Api.MobileAds..cctor () [0x00000] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0
Rethrow as TypeInitializationException: The type initializer for 'GoogleMobileAds.Api.MobileAds' threw an exception.
at HelperAdMob.Start () [0x00000] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0


I saw someone else has also posted it here (https://github.com/googleads/googleads-mobile-unity/issues/854)

Please help.

Regards,
Harsh Mehta


mobileadssdk...@google.com

unread,
Apr 12, 2019, 3:47:40 PM4/12/19
to Harsh Mehta, Google Mobile Ads SDK Developers
Hello Harsh,

Thanks for reaching out to us. Are you seeing the error with the latest version of the plugin? Can you make sure that you update your AppId through this method. Can you please share the complete device logs and a sample project for us if you are able to reproduce the issue?

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

On 04/12/19 07:15:31 hars...@gmail.com wrote:
Hi Nikita,

I have also been facing this issue.

I get an exception at MobileAds.Initialize(appId) itself.

I have tried the same code mentioned above and get the same isue.

NullReferenceException: Object reference not set to an instance of an object
at GoogleMobileAds.Api.MobileAds.GetMobileAdsClient () [0x00016] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0
at GoogleMobileAds.Api.MobileAds..cctor () [0x00000] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0
Rethrow as TypeInitializationException: The type initializer for 'GoogleMobileAds.Api.MobileAds' threw an exception.
at HelperAdMob.Start () [0x00000] in <1ec1d43b70e948ad8f07c11a7d63d57a>:0


I saw someone else has also posted it here (https://github.com/googleads/googleads-mobile-unity/issues/854)

Please help.

Regards,
Harsh Mehta




On Thursday, March 1, 2018 at 2:16:50 AM UTC+5:30, mobileadss...@google.com wrote:
Hi Nikita,

Thanks for getting back to us. For better tracking purposes, please continue the discussion on forum and use the "Reply Privately to Author" option only when sending sensitive information.

Regarding the issue with the project that you have shared, I'm unable to open the project for some reason. I don't notice any particular issue with your implementation and was wondering whether you are still noticing the same issue? Can you send us the device logs again?

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

NullReferenceException: Object reference not set to an instance of an object
GoogleMobileAds.Api.RewardBasedVideoAd..ctor () (at Assets/Plugins/GoogleMobileAds/Api/RewardBasedVideoAd.cs:40)
GoogleMobileAds.Api.RewardBasedVideoAd..cctor () (at Assets/Plugins/GoogleMobileAds/Api/RewardBasedVideoAd.cs:25)
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for GoogleMobileAds.Api.RewardBasedVideoAd
AdvertisementTest.Start () (at Assets/Plugins/AdvertisementTest.cs:25)


Is there any reason this might be happening? I'm not sure where to begin looking, and i've searched everywhere and couldn't find a solution. I have plugin v3.8.0 running on Unity 2017.1.1p4

--

---

Harsh Mehta

unread,
Apr 13, 2019, 2:03:25 AM4/13/19
to Google Mobile Ads SDK Developers
Hi Deepika,

(Replied privately. This is for reference for others. Link to sample project removed in public message)

Thank you for your quick response.


Please find Sample Project I used here. It contains
APK - Android.apk
Logs - adb_logcat_output.log
Sample Project - New Unity Project

I have used the following versions
Unity Version: 2018.3.8f1 (fc0fe30d6d91) Personal
Google Mobile Ads Unity Plugin: v3.16 (from https://github.com/googleads/googleads-mobile-unity/releases)

Any help would be highly appreciated.

Regards,
Harsh Mehta

Harsh Mehta

unread,
Apr 13, 2019, 9:50:25 AM4/13/19
to Google Mobile Ads SDK Developers
Hi Deepika,

I found a solution for this.

It looks like Unity was stripping the code out for Reflection. Documented here.

To solve this issue, one can either
1. Add the following lines in GoogleMobileAdsClientFactory.cs

using UnityEngine.Scripting;
[assembly: Preserve]

OR 

2. Change the "Managed Stripping Level" to Low or less.



I hope this is helpful to others.

Regards,
Harsh Mehta

mobileadssdk...@google.com

unread,
Apr 15, 2019, 12:13:51 PM4/15/19
to Harsh Mehta, Google Mobile Ads SDK Developers
Hello Harsh,

Thanks for sharing this. This will be definitely helpful for the community users. 

Regards,
Deepika Uragayala
Mobile Ads SDK Team
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+ page:
    http://googleadsdeveloper.blogspot.com
    https://plus.google.com/115658573333388777174/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

--

---
You received this message because you are subscribed to the Google Groups "Google Mobile Ads SDK Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-admob-ads-sdk+unsub...@googlegroups.com.

To post to this group, send email to google-admob-ads-sdk@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages