Android admob无法加载广告

时间:2016-04-26 18:31:32

标签: android admob

我正在尝试广告添加到我的应用程序中,我看到某处此错误可能意味着我的代码很好它只是admob没有添加返回但实际上我正在使用测试模式所以我无法理解什么是错的。这是我的xml文件:

<?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>

我的活动:

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();
    }

}

我的strings.xml(如果需要):

<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>

我还在AndroidManifest.xml中添加了Internet权限,而Google在gradle.build中添加了服务(我添加到Module.app而不是项目,是不是很好?)

我删除了一些与广告无关的部分,如果需要别的东西,就说。感谢。

编辑:LOGCAT过滤到广告:

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

1 个答案:

答案 0 :(得分:3)

您应该发布build.gradle文件。确保在应用的build.gradle文件中正确引用相关性。打开YourProject/app/build.gradle并确保您已指定如下:

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