简体   繁体   中英

Android admob failed to load ad

I am trying to ad adds to my application, I saw somewhere this error can mean my code is fine it's just admob doesn't have an add to return but actually I am using testing mode so I can't understand what's wrong. Here's my xml file:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/main3con"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main3">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        ads:adSize="BANNER"
        ads:adUnitId="@string/banner_ad_unit_id"></com.google.android.gms.ads.AdView>

</RelativeLayout>

And my Activity :

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
public class main3 extends Activity {
    private AdView mAdView;
 @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main3);

        mAdView = (AdView) findViewById(R.id.adView);
        AdRequest request = new AdRequest.Builder()
                .addTestDevice("AdRequest.DEVICE_ID_EMULATOR")
                .addTestDevice("207B846CF80A463F4B3150638CF7D2D0") // I don't know if it's okay to show.
                .build();
        mAdView.loadAd(request);
    }

    @Override
    public void onResume() {
        super.onResume();
        mAdView.resume();
    }

    @Override
    public void onPause() {
        mAdView.pause();
        super.onPause();
    }

    @Override
    public void onDestroy() {
        mAdView.destroy();
        super.onDestroy();
    }

}

My strings.xml (if needed):

<resources>
    <string name="app_name">Deck Randomizer - Clash Royale</string>
    <string name="action_settings">Settings</string>
    <string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
</resources>

And I also added Internet permission in AndroidManifest.xml, And Google play services in gradle.build (I added into Module.app and not project, is it fine?)

I deleted some parts aren't connected to the ads, if something else needed, just say. Thanks.

EDIT: LOGCAT filtered to ads:

04-27 17:27:29.101 2171-2171/com.clash.deckrandomizer D/DynamitePackage: Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
04-27 17:27:29.481 2171-2171/com.clash.deckrandomizer I/Ads: Starting ad request.
04-27 17:27:30.011 2171-2291/com.clash.deckrandomizer W/Ads: There was a problem getting an ad response. ErrorCode: 2
04-27 17:27:30.011 2171-2171/com.clash.deckrandomizer I/Ads: Scheduling ad refresh 60000 milliseconds from now.
04-27 17:27:30.011 2171-2171/com.clash.deckrandomizer W/Ads: Failed to load ad: 2

You should post your build.gradle file. Make sure you properly reference the dependency in your app's build.gradle file. Open YourProject/app/build.gradle and make sure you've specified like this:

...
dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.google.android.gms:play-services-ads:8.4.0'
    }
...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM