更新到'com.google.android.gms:play-services-ads:17.1.2'后,Admob广告无法加载

时间:2019-02-04 12:24:20

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

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

查看文档后,我意识到您必须在Launch活动和清单中初始化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'

这是清单的一个片段

   <?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>

我的Strings.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广告有关的依存关系时,您还需要考虑什么?

1 个答案:

答案 0 :(得分:0)

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

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