尝试使用Firebase Admob广告时,我遇到了崩溃问题。我按照指南,但我仍然得到这个奇怪的错误:
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);
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" />
答案 0 :(得分:1)
此类错误表明可能的原因。
您运行该应用程序的设备可能不支持您正在使用的SDK元素。
但在大多数情况下,由于gms
中build.gradle
库的版本升级,它们只是随机错误。
在build.gradle
依赖项中恢复以前版本的gms,错误应该消失。等到谷歌发布下一个版本,然后通过版本升级更新库依赖项。
答案 1 :(得分:1)
您是否在破坏之前更新了SDK?
有两个build.gradle
个文件,root\build.gradle
中的项目1和root\app\build.gradle
中的模块1。打开项目build.gradle
文件。
浏览所有版本号(buildToolsVersion,compile,..)并根据Android Studio在将鼠标光标悬停在其上时提供的提示更新它们。
如果您不解决问题,请转到file->settings->'android SDK'->'SDK tools'
并更新所有工具。