【问题标题】:AdMob not work on real deviceAdMob 无法在真实设备上运行
【发布时间】:2019-10-28 23:39:52
【问题描述】:

我已使用本指南在我的应用中显示 AdMob 横幅 https://firebase.google.com/docs/admob/android/quick-start 我的问题是 AdMob 横幅只显示在我的测试设备上,像这样 但在真实设备上我什么都看不到 我在 gradle 文件中的依赖项是:

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'

这是我的代码:

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

这是我的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>

它不起作用。

这是我的应用程序 的屏幕截图。

我的代码是

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

在我的 AdMob 帐户中,我看到了这个

如果我添加 .addTestDevice("***") 我的logcat是

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

【问题讨论】:

  • 从您的设备共享日志..您的 adUnitId 可能不正确,尝试用新 id 更改它?
  • 我添加了我的 logcat

标签: android firebase admob


【解决方案1】:

此代码用于测试 admob 广告。我认为,您遵循了测试广告教程。

您需要在 admob 帐户中创建自己的应用程序,并将您的广告单元包含在初始化部分中。

参考链接:https://support.google.com/admob/answer/3052638

您的活动代码。

            MobileAds.initialize(getApplicationContext(), "Your own admob ad-unit");

            AdView mAdView = (AdView) findViewById(R.id.adView);
            AdRequest adRequest = new AdRequest.Builder().build();
            mAdView.loadAd(adRequest);

这四行就够了。除此之外一切都很好。

注意:不要测试您真正的 admob 广告单元。如果是这样,谷歌有机会终止您的 admob 帐户。

当您在 Play 商店中发布应用时,您需要使用真实的广告单元。

【讨论】:

  • 我刚刚创建了一个 AdMob 帐户,在我的代码中,我把从应用管理页面获取的应用 ID 放入了 AdMob。
  • 您是说广告单元?您是否更改了那 4 行代码?然后,生成签名的应用程序,即发布构建并将您的应用程序发布到 Google Play 商店。然后,从那里下载并检查。
  • 我用这四行代码更改了代码,我已经发布了应用程序。但是如何在不删除我的帐户的情况下在真实设备上进行测试呢?
  • 只需在您的设备上下载。真正的广告将显示。不要点击那些广告。你可以看到广告。但是,那太有限了。 Becoz,广告发布商为这些广告向谷歌付费。谷歌没有给出关于开发者如何测试真实广告的特定规范。但是,给出了不测试真实广告的警告。如果是这样,他们只是禁用了您的 admob 帐户,并没有给您原因或下一次机会。
  • 我认为,他们会将您的 google 开发者帐户和设备的 play-store 帐户关联起来,并像开发者测试真实广告一样匹配。因此,从其他设备下载具有不同的谷歌帐户作为播放商店帐户来测试真实广告。这种方法也不推荐一种。但是,无论哪种方式都不要点击广告。因为每次点击都会算作后端的广告点击。
【解决方案2】:

检查您的日志,您会发现一条错误消息,提示您使用这行代码将您的设备添加为测试设备

`AdSettings.addTestDevice("You will find the Key in your logs");`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2014-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多