我的应用崩溃是因为 Firebase AdMob 依赖项颤动



我按照这里的说明进行操作:https://pub.dartlang.org/packages/firebase_admob#-readme-tab-但问题是,每当我添加并仅添加行firebase_admob:^0.8.0 + 3时,它就会崩溃。它只是眨眼打开并死亡。

 environment:
  sdk: ">=2.1.0 <3.0.0"
dependencies:
  cloud_firestore: ^0.9.13+1
  dependencies: ^0.1.5 # this was test if app crash on dependencies and seems not.
  #firebase_admob: ^0.8.0+3
  #admob_flutter: ^0.1.2
  flutter:
    sdk: flutter
  # firebase_core: ^0.2.5  # add dependency for Firebase Core
  cupertino_icons: ^0.1.2
dev_dependencies:
  flutter_test:
    sdk: flutter

# For information on the generic Dart part of this file, see the
# following page: https://www.dartlang.org/tools/pub/pubspec
# The following section is specific to Flutter.

有人有同样的问题吗,或者有人可以帮助我解决这个问题吗?

就我而言,我在标签下添加了meta-data标签activity但无法弄清楚。因此,对于那些可能像我一样犯了这个愚蠢错误的人,请遵循:

用于添加应用程序 ID 的meta-data标记需要添加到位于application标记下的androidappsrcmain AndroidManifest.xml中,而不是activity标记下,如 NormalTheme 或 SplashScreenDrawable 的meta-data标记activity标记下提到。

例如:

 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.appname">
   <application android:label="[Your AppName]" android:icon="@mipmap/ic_launcher">
        <meta-data android:name="com.google.android.gms.ads.APPLICATION_ID" android:value="[Your APP_ID]" />
          <activity android:name=".MainActivity" android:launchMode="singleTop" .......

尝试将依赖项版本降级为 firebase_admob: ^0.8.0+1

将 firebase_core: ^0.3.0 添加到依赖项后,它开始工作。

在 AndroidManifest 中更新 ADMOB APPLICATION_ID元数据.xml

<application android:name="io.flutter.app.FlutterApplication" android:label="firebase_admob_example" android:icon="@mipmap/ic_launcher">
    <meta-data
        android:name="com.google.android.gms.ads.APPLICATION_ID"
        android:value="ca-app-pub-3940256099942544~3347511713"/>
    <activity android:name=".MainActivity"
              android:launchMode="singleTop"
              android:theme="@android:style/Theme.Black.NoTitleBar"
              android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection"
              android:hardwareAccelerated="true"
              android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"/>
            <category android:name="android.intent.category.LAUNCHER"/>
        </intent-filter>
    </activity>
</application>

https://github.com/flutter/plugins/blob/master/packages/firebase_admob/example/android/app/src/main/AndroidManifest.xml

我遇到了同样的错误,我修复了它(((。必须将元数据标记粘贴到应用程序标记而不是活动下。

最新更新