颤抖fireabse_admob缺少google_app_id

时间:2020-08-24 08:20:42

标签: flutter admob

我搜索并尝试了一些解决方案,但对我而言不起作用。

AndroidManifest.xml底部

import os
from os import path
import pathlib
import shutil


path_ = input("Directory: ")
file_list = os.listdir(path_)  
os.chdir(path_)
current_directory = os.getcwd()

e = []
a = 0

for i in file_list:
    ext = os.path.splitext(i)[1][1:] 
    e.append(ext)  
    # print("Ext:", ext)

for j in range(len(e)):
    if e[j] == ",":
        j = j + 1
        continue
    os.mkdir(str(j)) 
    os.rename(str(j), e[j])  
    new_folder = e[j]

    for f in os.listdir(current_directory):
        new_directory = os.chdir(new_folder)  
        if f == ",":
            f +=1
            continue
        shutil.move(os.path.join(current_directory), str(new_directory))
        #print("it is moved")
    print(os.path.dirname(os.path.abspath(str(e[j]))))

在AdvertClass中

<meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-xxxxx116788401~8xxxxxxxxx"/>

build.gradle将android文件转换为按钮

import 'dart:io';

class AdvertService {
  static final AdvertService _instance = AdvertService._internal();
  factory AdvertService() => _instance;
  MobileAdTargetingInfo _targetingInfo;
  final String _bannerAd = Platform.isAndroid
      ? 'ca-app-pub-6xxxxxxxxx01/xxxxxx5'
      : 'ca-app-pub-67xxxxxxxx01/2xxxxxx';

  AdvertService._internal() {
    _targetingInfo = MobileAdTargetingInfo();
  }
  showBanner() {
    print(_bannerAd);
    BannerAd banner = BannerAd(
        adUnitId: _bannerAd,
        size: AdSize.smartBanner,
        targetingInfo: _targetingInfo);

    banner
      ..load()
      ..show();
    banner.dispose();
  }
}

此代码可用于测试ID

android {
    compileSdkVersion 28

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.example.flutter_app"
        minSdkVersion 28
        targetSdkVersion 28
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
    }
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"   
}
apply plugin: 'com.google.gms.google-services'

但是当我将其更改为admob id时出现错误

Admob error

 InterstitialAd(adUnitId: InterstitialAd.testAdUnitId , targetingInfo: _targetingInfo);

我现在也看到它说

Firebase error 但是我的pubsec.yaml有了

I got verified Admob account.
I created key
I added my test device in 
 _targetingInfo = MobileAdTargetingInfo( testDevices: <String>["54a0a4f2"]);

我创建了一个Firebase应用程序,下载了json文件并添加了它,然后它说了这一步,但我找不到它

Google json file

1 个答案:

答案 0 :(得分:0)

缺少google_app_id的错误仅是因为您没有实施Firebase Analytics,它只是一个提醒,并不影响广告。

在显示横幅广告之前使用appID初始化AdMob

FirebaseAdMob.instance.initialize(appId: appId);

还设置测试设备ID Found in your Admob error,以防止在调试模式下展示真实广告

MobileAdTargetingInfo(
  ...
  testDevices: <String>["Your device id"], // Android emulators are considered test devices
);

真实广告将通过以下步骤显示:

  1. 已验证 AdMob帐户。
  2. Sign Your App
  3. 如果已在“定位信息”中设置了设备测试ID,则构建发布
  4. Connect to Firebase Project