将广告添加到我的 flutter 应用程序解决了许多错误

Adding ads to my flutter app resolves in many errors

当我尝试按照 firebase 和 admobs 告诉我的所有操作向我的应用添加广告时,我遇到了很多错误。 首先,当我将此行添加到依赖项中 android 文件夹 implementation 'com.google.android.gms:play-services-ads:19.3.0' 中的 build.gradle 时,出现此错误 `

失败:构建失败,出现异常。

Could not find method implementation() for arguments [com.google.android.gms:play-services-ads:19.3.0] on object of type org.gradle.api.internal.artifacts.dsl.dependencies.DefaultDependencyHandler.

` 另外,当我在主文件中导入 firebase.dart 时,我得到了这个大错误

Compiler message:
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/top_level.dart:1:8: Error: Not found: 'dart:html'
import 'dart:html';
       ^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.2/lib/js.dart:8:1: Error: Not found: 'dart:js'
export 'dart:js' show allowInterop, allowInteropCaptureThis;
^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/js-0.6.2/lib/js_util.dart:8:1: Error: Not found: 'dart:js_util'
export 'dart:js_util';
^

BUILD FAILED in 1s
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart:306:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
 - 'Auth' is from 'package:firebase/src/auth.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var nextWrapper = allowInterop((firebase_interop.UserJsImpl user) {
                        ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart:310:26: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
 - 'Auth' is from 'package:firebase/src/auth.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var errorWrapper = allowInterop((e) => _changeController.addError(e));
                         ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart:340:25: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
 - 'Auth' is from 'package:firebase/src/auth.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var nextWrapper = allowInterop((firebase_interop.UserJsImpl user) {
                        ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart:345:11: Error: The method 'allowInterop' isn't defined for the class 'Auth'.
 - 'Auth' is from 'package:firebase/src/auth.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/auth.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
          allowInterop((e) => _idTokenChangedController.addError(e));
          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart:164:9: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
 - 'DatabaseReference' is from 'package:firebase/src/database.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
        allowInterop((update) => jsify(transactionUpdate(dartify(update))));
        ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart:166:26: Error: The method 'allowInterop' isn't defined for the class 'DatabaseReference<T>'.
 - 'DatabaseReference' is from 'package:firebase/src/database.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    var onCompleteWrap = allowInterop(
                         ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart:301:24: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
 - 'Query' is from 'package:firebase/src/database.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    var callbackWrap = allowInterop((database_interop.DataSnapshotJsImpl data,
                       ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart:325:30: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
 - 'Query' is from 'package:firebase/src/database.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    jsObject.once(eventType, allowInterop(
                             ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart:402:22: Error: The method 'allowInterop' isn't defined for the class 'DataSnapshot'.
 - 'DataSnapshot' is from 'package:firebase/src/database.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/database.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    var actionWrap = allowInterop((d) => action(DataSnapshot.getInstance(d)));
                     ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart:72:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
 - 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      final nextWrapper = allowInterop((payload) {
                          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart:75:28: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
 - 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      final errorWrapper = allowInterop((e) {
                           ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart:87:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
 - 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      final nextWrapper = allowInterop((payload) {
                          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart:97:27: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
 - 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      final nextWrapper = allowInterop((_) => null);
                          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart:98:28: Error: The method 'allowInterop' isn't defined for the class 'Messaging'.
 - 'Messaging' is from 'package:firebase/src/messaging.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/messaging.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      final errorWrapper = allowInterop((e) {
                           ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart:317:11: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
 - 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
          allowInterop((storage_interop.UploadTaskSnapshotJsImpl data) {
          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart:321:26: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
 - 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var errorWrapper = allowInterop((e) => _changeController.addError(e));
                         ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart:322:26: Error: The method 'allowInterop' isn't defined for the class 'UploadTask'.
 - 'UploadTask' is from 'package:firebase/src/storage.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/storage.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var onCompletion = allowInterop(() => _changeController.close());
                         ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/top_level.dart:194:7: Error: Method not found: 'hasProperty'.
  if (js.hasProperty(error, 'message')) {
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/top_level.dart:195:19: Error: Method not found: 'getProperty'.
    var message = js.getProperty(error, 'message');
                  ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:29:7: Error: Method not found: 'hasProperty'.
  if (util.hasProperty(jsObject, 'firestore') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:30:7: Error: Method not found: 'hasProperty'.
      util.hasProperty(jsObject, 'id') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:31:7: Error: Method not found: 'hasProperty'.
      util.hasProperty(jsObject, 'parent')) {
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:37:7: Error: Method not found: 'hasProperty'.
  if (util.hasProperty(jsObject, 'latitude') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:38:7: Error: Method not found: 'hasProperty'.
      util.hasProperty(jsObject, 'longitude') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:44:15: Error: Method not found: 'getProperty'.
  var proto = util.getProperty(jsObject, '__proto__');
              ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:46:7: Error: Method not found: 'hasProperty'.
  if (util.hasProperty(proto, 'toDate') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:47:7: Error: Method not found: 'hasProperty'.
      util.hasProperty(proto, 'toMillis')) {
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:52:7: Error: Method not found: 'hasProperty'.
  if (util.hasProperty(proto, 'isEqual') &&
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:53:7: Error: Method not found: 'hasProperty'.
      util.hasProperty(proto, 'toBase64')) {
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:67:24: Error: Method not found: 'getProperty'.
    map[key] = dartify(util.getProperty(jsObject, key));
                       ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:91:17: Error: Method not found: 'newObject'.
    var jsMap = util.newObject();
                ^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:93:7: Error: Method not found: 'setProperty'.
      util.setProperty(jsMap, key, jsify(value));
      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:116:12: Error: Method not found: 'allowInterop'.
    return allowInterop(dartObject);
           ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:124:5: Error: Method not found: 'callMethod'.
    util.callMethod(jsObject, method, args);
    ^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:139:19: Error: Method not found: 'promiseToFuture'.
    value = await util.promiseToFuture(thenable);
                  ^^^^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:141:9: Error: Method not found: 'hasProperty'.
    if (util.hasProperty(e, 'code')) {
        ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:152:27: Error: Method not found: 'allowInterop'.
  return PromiseJsImpl<S>(allowInterop((
                          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:165:5: Error: Method not found: 'allowInterop'.
    allowInterop(c.completeError);
    ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:173:22: Error: Method not found: 'getProperty'.
  String get code => util.getProperty(_source, 'code');
                     ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:176:25: Error: Method not found: 'getProperty'.
  String get message => util.getProperty(_source, 'message');
                        ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:179:22: Error: Method not found: 'getProperty'.
  String get name => util.getProperty(_source, 'name');
                     ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:182:32: Error: Method not found: 'getProperty'.
  Object get serverResponse => util.getProperty(_source, 'serverResponse');
                               ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/utils.dart:185:23: Error: Method not found: 'getProperty'.
  String get stack => util.getProperty(_source, 'stack');
                      ^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:105:30: Error: The method 'allowInterop' isn't defined for the class 'Firestore'.
 - 'Firestore' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    var updateFunctionWrap = allowInterop((transaction) =>
                             ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:306:11: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
 - 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
          allowInterop((firestore_interop.DocumentSnapshotJsImpl snapshot) {
          ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:310:26: Error: The method 'allowInterop' isn't defined for the class 'DocumentReference'.
 - 'DocumentReference' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
      var errorWrapper = allowInterop((e) => controller.addError(e));
                         ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:445:9: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
 - 'Query' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
        allowInterop((firestore_interop.QuerySnapshotJsImpl snapshot) {
        ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:449:24: Error: The method 'allowInterop' isn't defined for the class 'Query<T>'.
 - 'Query' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
    var errorWrapper = allowInterop((e) => controller.addError(e));
                       ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart:775:9: Error: The method 'allowInterop' isn't defined for the class 'QuerySnapshot'.
 - 'QuerySnapshot' is from 'package:firebase/src/firestore.dart' ('../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/firestore.dart').
Try correcting the name to the name of an existing method, or defining a method named 'allowInterop'.
        allowInterop((s) => callback(DocumentSnapshot.getInstance(s)));
        ^^^^^^^^^^^^
../../dartsdk/flutter/.pub-cache/hosted/pub.dartlang.org/firebase-7.3.0/lib/src/interop/js_interop.dart:17:7: Error: Method not found: 'hasProperty'.
  if (util.hasProperty(jsObject, 'toDateString')) {
      ^^^^^^^^^^^
../../dartsdk/flutter/packages/flutter/lib/src/painting/_network_image_web.dart:88:12: Error: Method not found: 'webOnlyInstantiateImageCodecFromUrl'.
    return ui.webOnlyInstantiateImageCodecFromUrl(resolved, // ignore: undefined_function
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Exception: Gradle task assembleDebug failed with exit code 1

有人请帮助。 这是我的 app/build.gradle 文件

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    compileSdkVersion 28

    lintOptions {
        disable 'InvalidPackage'
    }

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

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }
}

flutter {
    source '../..'
}

这是我的 android/build.gradle 文件。

buildscript {
    repositories {
        google()
        jcenter()
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.0'
        implementation 'com.google.android.gms:play-services-ads:19.3.0'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
    }
}

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
    delete rootProject.buildDir
}

在 app/build.gradle 文件中你丢失了,

apply plugin: 'com.google.gms.google-services'

而且你不需要implementation 'com.google.android.gms:play-services-ads:19.3.0'

您应该使用 Admob Flutter 插件 (https://pub.dev/packages/firebase_admob)