簡體   English   中英

更新到'com.google.android.gms:play-services-ads:17.1.2'后,Admob廣告無法加載

[英]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廣告將不再加載。 我使用版本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廣告的依賴關系時,您還需要考慮什么?

我遇到了類似的問題-測試廣告有效,但我卻沒有。 我讀過某個地方,他們不會在您每次打開應用程序時加載,並且將它們添加到您的應用程序中需要幾個小時才能顯示出來。 只需在Google AdMob控制台上查看展示次數(如果不是零),它們就會顯示在某人的手機上。

您是否在Google Play上更新了應用版本? 如果還沒有,那就去做。 這樣,您可以測試Google AdMob控制台解決方案,或者讓我知道應用程序的名稱,以便檢查自己是否看到廣告。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM