Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

AdMob and custom Assemblies

Discussion in 'Android' started by Nightstriker, Jun 22, 2019.

  1. Nightstriker

    Nightstriker

    Joined:
    Feb 11, 2018
    Posts:
    11
    Hi,

    I've been using custom assemblies through my project to make everything more modular and I had to in the past create assemblies of plugins as well. I tried to do the same for AdMob but I get the error below.

    Code (CSharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. GoogleMobileAds.Api.MobileAds.GetMobileAdsClient () (at Assets/GoogleMobileAds/Api/MobileAds.cs:50)
    3. GoogleMobileAds.Api.MobileAds..cctor () (at Assets/GoogleMobileAds/Api/MobileAds.cs:24)
    4. Rethrow as TypeInitializationException: The type initializer for 'GoogleMobileAds.Api.MobileAds' threw an exception.
    5. AdMobInitialize.Awake () (at Assets/BasicMobile/Scripts/Ads/AdMobInitialize.cs:20)
    Deleting all the assemblies resolves the issue, but I was wondering if there is a better way.

    To replicate the problem:

    - Empty Unity project
    - Import AdMob
    - Create an assembly for the adMob
    - Create a script Like so:

    Code (CSharp):
    1. string appId = "myAppID" //Here you put the actual ID, or a test ID
    2. MobileAds.Initialize(appId);
    3.  
    - Create custom assembly for the script and reference the AdMob assembly to it.

    I would appreciate some help. Am I using assemblies wrong?
     
    Baydogan likes this.
  2. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    Hi Nightstriker,

    I am having the same issue with the AdMob native library.

    Without asmdef file everything works fine but when I add asmdef, MobileAds.Initialize throws null reference exception.

    I think it is related to il2cpp code stripping but I could not find a way to prove it.

    If you solved this problem please tell us the solution.

    Thanks.