Google Admob无法解析导致Android游戏崩溃的类

时间:2020-06-01 00:27:22

标签: unity3d admob

我正在Unity中构建一个Android游戏,并希望加入Google AdMob。我按照Google开发人员官方页面上的说明进行操作。该游戏在Unity中运行正常,并且构建时没有问题。这款游戏可以在我的设备上正常运行,除非我切换到应该加载,展示广告的场景,然后收到以下错误消息:

错误AndroidRuntime:java.lang.NoClassDefFoundError:失败 分辨率:Lcom / google / android / gms / ads / InterstitialAd;

错误AndroidRuntime:由以下原因引起:java.lang.ClassNotFoundException: 在路径:

上找不到类“ com.google.android.gms.ads.InterstitialAd”

错误Unity:AndroidJavaException:java.lang.ClassNotFoundException: com.google.android.gms.ads.AdRequest $ Builder

错误Unity:由以下原因引起:java.lang.ClassNotFoundException:找不到 路径上的类“ com.google.android.gms.ads.AdRequest $ Builder”:错误 Unity:AndroidJavaException:java.lang.ClassNotFoundException: com.google.android.gms.ads.initialization.OnInitializationCompleteListener

错误Unity:由以下原因引起:java.lang.ClassNotFoundException:找不到 类 “ com.google.android.gms.ads.initialization.OnInitializationCompleteListener” 在路径上:

我已经尝试过重新安装Google Ads插件,解决依赖关系并切换到自己的JDK。这些都没有解决问题。我使用adMob的课程是:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using GoogleMobileAds.Api;

public class AdsManager : MonoBehaviour
{
     private string _appID = "APP_ID"; // admob app id
     private string _testInterstitial = "TEST_ID"; // admob test interstitial ad id

     private InterstitialAd inter; // interstitial ad object

     // Start is called before the first frame update
     void Start()
     {
         // Initialize the Google Mobile Ads SDK.
         MobileAds.Initialize(_appID);
         Debug.Log("initialized app id");
     }

     public void RequestInterstitialAd()
     {
         // Initialize an InterstitialAd.
         this.inter = new InterstitialAd(_testInterstitial);

         // Create an empty ad request.
         AdRequest request = new AdRequest.Builder().Build();
         // Load the interstitial with the request.
         this.inter.LoadAd(request);
     }

     public void ShowInterstitialAd()
     {
         if (this.inter.IsLoaded())
         {
             this.inter.Show();
         }
         else 
         {
             Debug.Log("Interstitial ad not yet loaded");
         }
     }

     public void DestroyInterstitialAd()
     {
         if (inter != null)
         {
             inter.Destroy();
         }
     }
}

感谢您的任何帮助,谢谢。

0 个答案:

没有答案