【问题标题】:Admob Ads don't load after updating to 'com.google.android.gms:play-services-ads:17.1.2'更新到“com.google.android.gms:play-services-ads:17.1.2”后 Admob 广告无法加载
【发布时间】:2019-02-04 12:24:19
【问题描述】:

我最近将 'com.google.android.gms:play-services-ads' 依赖项更新为 17.1.2,我的 admob 广告将不再加载。我使用版本 11 很长时间了,从来没有任何问题,但更新后它们将不再显示。

查看文档后,我意识到您必须在启动活动和清单中初始化 APP-ID,所以我调整了代码,但广告仍然没有显示,所以我尝试了 Admobs 测试广告 ID 和他们加载正常。

所以问题不能出在admob的实现上,对吧?

这里是我的 build.gradle

     buildscript {
repositories {
    maven { url 'https://maven.fabric.io/public' }
}

dependencies {
    classpath 'io.fabric.tools:gradle:1.25.4'
}
}
    apply plugin: 'com.android.application'
 apply plugin: 'io.fabric'

   repositories {
maven { url 'https://maven.fabric.io/public' }
 }


  android {
signingConfigs {
    config {
        keyAlias 'XX'
        keyPassword 'XX'
        storeFile file('XX')
        storePassword 'XX'
    }
    lintOptions {
        checkReleaseBuilds false
    }
}
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
    applicationId "XX"
    minSdkVersion 17
    targetSdkVersion 28
    versionCode XX
    versionName "XX"


    multiDexEnabled true
}
buildTypes {
    release {
        minifyEnabled false
        proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        debuggable false
        signingConfig signingConfigs.config
    }
}

dexOptions {

    preDexLibraries = false
    javaMaxHeapSize "4g" // 2g should be also OK
}

 }


dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
testImplementation 'junit:junit:4.12'

implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support:animated-vector-drawable:28.0.0'
// https://mvnrepository.com/artifact/com.android.support/customtabs
implementation group: 'com.android.support', name: 'customtabs', version: '28.0.0'
implementation 'com.android.support:support-v4:28.0.0'
implementation 'com.google.android.gms:play-services-ads:17.1.2'
implementation 'com.google.firebase:firebase-ads:17.1.2'
implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.android.billingclient:billing:1.1'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.8'
implementation 'com.google.firebase:firebase-database:16.0.6'

  }

 apply plugin: 'com.google.gms.google-services'

这里是 Manifest 的 sn-p

   <?xml version="1.0" encoding="utf-8"?>

<!-- Include required permissions for Google Mobile Ads to run. -->
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission. WAKE_LOCK" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/appicon1"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/Theme.AppCompat.NoActionBar"
    >

    <!-- This meta-data tag is required to use Google Play Services. -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value=

            "@integer/google_play_services_version" />

    <activity android:name=".Splashscreen"

        android:label="@string/app_name"
        android:screenOrientation="portrait">

    <intent-filter>
        <action android:name="android.intent.action.MAIN" />

        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
    </activity>

    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>


    <!-- Include the AdActivity configChanges and theme. -->
    <activity
        android:name="com.google.android.gms.ads.AdActivity"
        android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
         />

    <uses-library android:name="org.apache.http.legacy" android:required="false" />
    <meta-data
        android:name="io.fabric.ApiKey"
        android:value="XXX" />
    <!-- Sa+mple AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="@string/google_app_id"
        />
</application>

我的字符串.xml

<string name="ad_unit_id" translatable="false">ca-app-pub-XXX/XX</string>
<string name="google_app_id" translatable="false">ca-app-pub-XXX~XX</string>
<string name="banner_ad_unit_id" translatable="false">ca-app-pub-XXX/XX</string>
<string name="reward_id" translatable="false">ca-app-pub-XXX/XX</string>

MAinactivity.class 的片段

  public AdView mAdView;
     @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

  MobileAds.initialize(this, getString(R.string.google_app_id));

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

因此,查看代码我真的看不出广告无法加载的原因。在升级与 admob 广告相关的依赖项时,您还有什么需要考虑的吗?

【问题讨论】:

  • 我对 com.google.firebase:firebase-ads:17.2.0 有同样的问题。你解决了吗?

标签: java android admob ads google-play-services


【解决方案1】:

我遇到了类似的问题 - 测试广告有效,但我自己的却没有。我在某处读到它们不会在您每次打开应用程序时加载,并且在您将它们添加到应用程序后需要几个小时才能显示出来。只需在 Google AdMob 控制台上查看展示次数 - 如果它不为零 - 他们出现在某人的手机上。

您是否在 Google Play 上更新了您的应用版本?如果你还没有,那就去做吧。这样您就可以测试 Google AdMob 控制台解决方案,或者让我知道应用的名称,以便我自己检查是否看到广告。

【讨论】:

  • 嘿,首先谢谢,不,我还没有更新它。我在商店里有一个在线版本,运行的是旧的 Google 广告版本,它运行良好。而且我不想在排序之前上传更新的内容。有邮箱地址,我可以把apk发给你吗?会超级好
  • 是的,它的 natasa2604@yahoo.com。
猜你喜欢
  • 2019-04-17
  • 1970-01-01
  • 1970-01-01
  • 2019-05-12
  • 2016-09-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多