2016-08-21 58 views
0

嘗試使用Firebase AdMob廣告時發生崩潰。我跟着指導,但我仍然得到這個奇怪的錯誤:Android AdMob - NoSuchMethodError:無靜態方法zzand()

java.lang.NoSuchMethodError: No static method zzand()Lcom/google/android/gms/common/zzc; in class Lcom/google/android/gms/common/zzc; or its super classes (declaration of 'com.google.android.gms.common.zzc' appears in /data/data/tech.timmo.terminalwatch/files/instant-run/dex/slice-com.google.android.gms-play-services-basement-9.4.0_0d08c875bcfdb7f644dc6c5ac5fbcb017cb05b7c-classes.dex) 
                     at com.google.android.gms.ads.internal.util.client.zza.zzar(Unknown Source) 
                     at com.google.android.gms.ads.internal.client.zzl.zza(Unknown Source) 
                     at com.google.android.gms.ads.internal.client.zzl.zzl(Unknown Source) 
                     at com.google.android.gms.ads.internal.client.zzag.zza(Unknown Source) 
                     at com.google.android.gms.ads.MobileAds.initialize(Unknown Source) 
                     at com.google.android.gms.ads.MobileAds.initialize(Unknown Source) 
                     at tech.timmo.terminalwatch.ConfigActivity$override.onCreate(ConfigActivity.java:77) 
                     at tech.timmo.terminalwatch.ConfigActivity$override.access$dispatch(ConfigActivity.java) 
                     at tech.timmo.terminalwatch.ConfigActivity.onCreate(ConfigActivity.java:0) 
                     at android.app.Activity.performCreate(Activity.java:6251) 
                     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1108) 
                     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2403) 
                     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2510) 
                     at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:4111) 
                     at android.app.ActivityThread.-wrap15(ActivityThread.java) 
                     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1369) 
                     at android.os.Handler.dispatchMessage(Handler.java:102) 
                     at android.os.Looper.loop(Looper.java:148) 
                     at android.app.ActivityThread.main(ActivityThread.java:5461) 
                     at java.lang.reflect.Method.invoke(Native Method) 
                     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726) 
                     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616) 

這是我在的onCreate()初始化該錯誤指向第一線MobileAds.initialise:

MobileAds.initialize(getApplicationContext(), getString(R.string.banner_ad_unit_id)); 
AdView adView = (AdView) findViewById(R.id.adView); 
adView.setAdSize(AdSize.SMART_BANNER); 
AdRequest adRequest = new AdRequest.Builder() 
     .addTestDevice("9A3855EFE9914A3C40BF5A33DABB4701") 
     .build(); 
adView.loadAd(adRequest); 

The xml:

<com.google.android.gms.ads.AdView 
    android:id="@+id/adView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    app:adSize="SMART_BANNER" 
    app:adUnitId="@string/banner_ad_unit_id" /> 

回答

1

這種類型的錯誤表明可能的原因。

您正在運行應用程序的設備可能不支持您正在使用的SDK元素。

但是在大多數情況下,它們只是由於版本升級build.gradle中的gms庫而引入的隨機錯誤。

回收您的build.gradle依賴關係中以前版本的gms,並且錯誤應該消失。等到google發佈下一個版本,然後通過版本升級更新庫依賴項。

1

在更新SDK之前,您是否更新了SDK?

有兩個build.gradle文件,項目一在root\build.gradle和模塊一在root\app\build.gradle。打開項目build.gradle文件。

查看所有版本號(buildToolsVersion,compile,..),並根據Android Studio在將鼠標光標懸停在它們上時提供的提示進行更新。

如果不解決您的問題,請去file->settings->'android SDK'->'SDK tools'並更新所有工具。

相關問題