首页 > 解决方案 > Admob 错误代码 2 - 广告加载失败:2

问题描述

我正在尝试在 android 中显示智能尺寸横幅,但广告没有显示,当我看到日志时它显示:I/Ads: Ad failed to load : 2. 我在互联网上搜索,发现问题是由于互联网连接造成的,但我的手机上有活跃且可靠的网络连接。下面是我的app毕业典礼:

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    implementation 'com.android.support:appcompat-v7:28.0.0'
    implementation 'com.android.support:design:28.0.0'
    implementation 'com.android.support.constraint:constraint-layout:2.0.0-alpha3'
    implementation 'com.android.support:support-v4:28.0.0'
    testCompile 'junit:junit:4.12'
    implementation 'com.airbnb.android:lottie:2.1.0'
    implementation 'com.mikhaellopez:circularimageview:3.2.0'
    implementation 'com.google.android.gms:play-services-ads:17.1.2'
}

以下是我的活动课:

MobileAds.initialize(this, Utils.ADMOB_APP_ID);
        mAdView = findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().addTestDevice("B2DD8C77E01892E0FF2A672FC77E2FF9").build();
        mAdView.loadAd(adRequest);

这是布局:

<com.google.android.gms.ads.AdView
            xmlns:ads="http://schemas.android.com/apk/res-auto"
            android:id="@+id/adView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_alignParentBottom="true"
            ads:adSize="SMART_BANNER"
            ads:adUnitId="@string/app_admob_id">
        </com.google.android.gms.ads.AdView>

这是与广告相关的一些错误日志:

W/Ads: Invoke Firebase method getInstance error.
    The Google Mobile Ads SDK will not integrate with Firebase. Admob/Firebase integration requires the latest Firebase SDK jar, but Firebase SDK is either missing or out of date
W/Ads: Not retrying to fetch app settings
I/Ads: Ad failed to load : 2

标签: androidadmob

解决方案


此问题最常发生在没有 Internet 连接时。


推荐阅读