Flutter google_mobile_ads 未显示广告 ID

Posted

技术标签:

【中文标题】Flutter google_mobile_ads 未显示广告 ID【英文标题】:Flutter google_mobile_ads not showing with ad id 【发布时间】:2022-01-11 21:26:54 【问题描述】:

我正在使用 google_mobile_ads 并验证了我的 admob 帐户并创建了广告单元,所有这些都至少有 2 天的历史。

但每当我更改广告 ID 时,在下面的代码中,广告都不会显示。我尝试构建一个发布 apk 并将其安装在我的手机上,但广告仍然没有显示,我还没有发布应用程序。

void loadRewardedAd()
    RewardedAd.load(
        adUnitId: RewardedAd.testAdUnitId,//when i put my ad id here it doesn't work
        request: AdRequest(),
        rewardedAdLoadCallback: RewardedAdLoadCallback(
          onAdLoaded: (RewardedAd ad) 
            rewardedAd = ad;
            adLoadsNumber = 0;
          ,
          onAdFailedToLoad: (LoadAdError error) 
            adLoadsNumber++;
            interStitialAd = null;

            if (adLoadsNumber <= 2) 
              loadAds();
            
          ,
        ));
  

  void showRewardedAd()
    rewardedAd.fullScreenContentCallback = FullScreenContentCallback(
      onAdShowedFullScreenContent: (RewardedAd ad) =>
          print('$ad onAdShowedFullScreenContent.'),
      onAdDismissedFullScreenContent: (RewardedAd ad) 
        print('$ad onAdDismissedFullScreenContent.');
        ad.dispose();
      ,
      onAdFailedToShowFullScreenContent: (RewardedAd ad, AdError error) 
        print('$ad onAdFailedToShowFullScreenContent: $error');
        ad.dispose();
      ,
      onAdImpression: (RewardedAd ad) => print('$ad impression occurred.'),
    );

    rewardedAd.show(
        onUserEarnedReward: (RewardedAd ad, RewardItem rewardItem) 
          this.gameEnded = false;
          this.livesLeft.value = 3;
        
    );

  
  void loadAds() 
    loadInterstitialAd();
    loadRewardedAd();
  

  void loadInterstitialAd()
    InterstitialAd.load(
        adUnitId: InterstitialAd.testAdUnitId,//same with this one
        request: AdRequest(),
        adLoadCallback:
        InterstitialAdLoadCallback(onAdLoaded: (InterstitialAd ad) 
          interStitialAd = ad;
          adLoadsNumber = 0;
        , onAdFailedToLoad: (LoadAdError e) 
          adLoadsNumber++;
          interStitialAd = null;

          if (adLoadsNumber <= 2) 
            loadInterstitialAd();
          
        ));
  

  void showInterstitialAd(bool isEnded) 
    if (interStitialAd == null) 
      return;
    

    interStitialAd.fullScreenContentCallback = FullScreenContentCallback(
      onAdDismissedFullScreenContent: (InterstitialAd ad) 
        ad.dispose();
      ,
      onAdFailedToShowFullScreenContent: (InterstitialAd ad, AdError error) 
        ad.dispose();
      ,
    );

    interStitialAd.show();
  

【问题讨论】:

我也签署了release apk 如果测试广告正在展示则完全没问题,Live Ads 需要相当长的时间才能展示。 好的,测试广告已显示。谢谢 【参考方案1】:

请检查您是否在控制台中添加了 Signed APK SHA。

【讨论】:

我已经使用docs.flutter.dev/deployment/android 使用密钥库对其进行了签名,但我没有使用 sha 对其进行签名,有必要这样做吗?

以上是关于Flutter google_mobile_ads 未显示广告 ID的主要内容,如果未能解决你的问题,请参考以下文章

[Flutter] flutter项目一直卡在 Running Gradle task 'assembleDebug'...

flutter 日志输出,Flutter打印日志,flutter log,flutter 真机日志

Flutter开发 Flutter 包和插件 ( Flutter 包和插件简介 | 创建 Flutter 插件 | 创建 Dart 包 )

flutter与原生混编(iOS)

Flutter-布局

如何解决flutter gradle build error?C:\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 991