Android admob无法加载广告
我试图在我的应用程序中添加广告,我发现这个错误可能意味着我的代码很好,只是admob没有要返回的添加,但实际上我正在使用测试模式,所以我无法理解出了什么问题。这是我的xml文件:Android admob无法加载广告,android,admob,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
<?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>
My strings.xml(如果需要):
你应该发布你的
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'
}
...
在logCat中,尝试过滤“广告”。你看到什么痕迹了吗?如果是这样,请将跟踪发布到此处,以便我们进行调试。有时,当互联网连接速度慢时(例如在3G网络上),广告不会显示。@AngelKoh补充道:)错误代码2(要么是互联网连接速度慢导致超时,要么是设备和谷歌服务器之间的时间差异太大)。这里有更多细节@AngelKoh我不知道,也尝试了多个设备和模拟器。@AngelKoh谢谢你解决了我的问题:)我实际上添加了这个。
<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>
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
...
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.android.gms:play-services-ads:8.4.0'
}
...