admob广告在更新到'com.google.android'后不会加载gms:play-services-ads:17.1.2'

vsikbqxv  于 2021-07-09  发布在  Java
关注(0)|答案(1)|浏览(363)

我最近更新了com.google.android。gms:play-services-ads'Dependencies到17.1.2,我的admob广告将不再加载。我使用版本11很长一段时间,从来没有任何问题,但更新后,他们不会再显示了。
在我看了文档之后,我意识到你必须在启动活动和清单中初始化app id,所以我调整了代码,但是广告仍然没有显示,所以我尝试了admobs测试广告id,它们可以正常加载。
所以问题不可能出在admob的实施上,对吧?
这是我的身材。grad尔

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>

我的字符串.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广告相关的依赖项时,是否还需要考虑其他事项?

pzfprimi

pzfprimi1#

我有类似的问题-测试广告的工作,但我自己的没有。我在某个地方读到,他们不会每次你打开你的应用程序时加载,而且在你将他们添加到你的应用程序后,他们需要几个小时才能出现。只要在GoogleAdMob控制台上,看到印象数——如果不是零——他们出现在某人的手机上。
你在googleplay上更新了你的应用程序版本了吗?如果你没有,就去做。这样你就可以测试googleadmob控制台解决方案,或者让我知道应用程序的名称,这样我就可以自己查看是否看到广告。

相关问题