AdMob not work on real device
I've used this guide for display an AdMob Banner in my app https://firebase.google.com/docs/admob/android/quick-start My problem is that the AdMob banner is only shown on my test device like this But on real device I don't see anything My dependencies in gradle file is:
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'de.hdodenhof:circleimageview:1.3.0'
compile 'com.android.support:support-v4:25.1.0'
compile 'com.google.firebase:firebase-core:10.0.1'
compile 'com.google.firebase:firebase-ads:10.0.1'
compile 'com.google.android.gms:play-services:10.0.1'
compile 'com.android.support:multidex:1.0.1'
testCompile 'junit:junit:4.12'
}
apply plugin: 'com.google.gms.google-services'
This is my code:
MobileAds.initialize(getContext(), "ca-app-pub-****");
AdRequest request = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("4F8D70E24813A8C1CFF9B07A47A4F484")
.setRequestAgent("android_studio:ad_template")
.build();
mAdView.loadAd(request);
And this is my xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.saffru.colombo.navigationdrawervideotutorial.MainFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/l_apos_onomastico_di_oggi"
android:id="@+id/textView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="100dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="@string/xxx"
android:id="@+id/textView3"
android:textColor="@color/verde1"
android:layout_below="@+id/textView2"
android:layout_centerHorizontal="true"
android:layout_marginTop="46dp" />
<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-****">
</com.google.android.gms.ads.AdView>
</RelativeLayout>
It doesn't work.
This is a screenshot of my app.
My code is
MobileAds.initialize(getContext(), "ca-app-pub-6864438797370510/3840785983");
AdView mAdView = (AdView) view.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
And in my AdMob account I see this
If I add .addTestDevice("***") My logcat is
02-19 22:07:28.379 2762-2762/com.saffru.colombo.onomastici2 W/System:
ClassLoader referenced unknown path:
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi-v7a
02-19 22:07:28.380 2762-2762/com.saffru.colombo.onomastici2 W/System:
ClassLoader referenced unknown path:
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi
02-19 22:07:28.392 2762-2762/com.saffru.colombo.onomastici2
I/FirebaseCrashApiImpl: FirebaseCrashApiImpl created by ClassLoader
p[DexPathList[[zip file"
/data/data/com.google.android.gms/app_chimera/m/0000000e/
DynamiteModulesC_GmsCore_prodmnc_xxhdpi_release.apk"],
nativeLibraryDirectories[/data/user/0/com.google.android.gms/
app_chimera/m/0000000e/n/armeabi-v7a,
/data/user/0/com.google.android.gms/app_chimera/m/0000000e/n/armeabi,
/vendor/lib, /system/lib]]]
02-19 22:07:29.145 2762-2762/com.saffru.colombo.onomastici2 W/System:
ClassLoader referenced unknown path:
/data/user/0/com.google.android.gms/app_chimera/m/0000000c/n/armeabi
02-19 22:07:29.230 2762-2878/com.saffru.colombo.onomastici2 W/System:
ClassLoader referenced unknown path:
/data/user/0/com.google.android.gms/app_chimera/m/0000000c/n/armeabi
02-19 22:07:29.295 2762-2888/com.saffru.colombo.onomastici2 D/OpenGLRenderer:
Use EGL_SWAP_BEHAVIOR_PRESERVED: true
This code for testing the admob ads. I think, You followed the test ads tutorial.
You need to create you own app in the admob account and include your ad-unit in initialize part.
The reference link : https://support.google.com/admob/answer/3052638
Your activity code.
MobileAds.initialize(getApplicationContext(), "Your own admob ad-unit");
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
These four line is enough. Other than this everything is fine.
Note: Don't test your real admob ad-unit. If so, There is chance to terminate your admob account by google.
You need to use your real ad-unit when you release app in play store.
检查你的日志,你会发现一个错误,说使用这行代码添加你的设备作为测试设备
`AdSettings.addTestDevice("You will find the Key in your logs");`
链接地址: http://www.djcxy.com/p/32388.html
上一篇: 在24小时前创建的AdMob ID仍然无法在应用中使用
下一篇: AdMob不适用于真实设备