android - AdMob 无法在真实设备上运行

标签 android firebase admob

我已使用本指南在我的应用中显示 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("***") 我的日志是

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

最佳答案

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

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

引用链接:https://support.google.com/admob/answer/3052638

您的 Activity 代码。

            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 广告单元。如果是这样,Google 可能会终止您的 admob 帐户。

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

关于android - AdMob 无法在真实设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42316165/

相关文章:

java - 膨胀类 android.support.v7.internal.widget.NativeActionModeAwareLayout 时出错

android - 将文件 Assets 打包成apk?

java - 如何从 firebase 读取并在评级栏中显示

ios - 如何禁用 Firebase pod 附带的 Google 登录?

android - Admob 与 pygame 在 android 中的集成

android - 当我最小化一个应用程序时,我应该如何处理再次运行我的应用程序?

android - ScrollView内部的MotionLayout在状态改变后不更新高度

android - Firebase 不发送 OTP

ios - admob 以编程方式刷新率

android - AdMob 运行时出现间歇性 java.lang.NoClassDefFoundError