如何将Admob正确添加到Flutter项目中?

时间:2018-12-21 14:04:18

标签: android firebase flutter admob

我有一个使用Firebase_Admob软件包的Flutter项目。一切正常,可在iOS上正常运行,但我的Android实例收到以下错误...

  
* The Google Mobile Ads SDK was initialized incorrectly. AdMob publishers    *
* App ID inside the AndroidManifest. Google Ad Manager publishers should     *
******************************************************************************

这就是我的AndroidManifest的样子...

<application
        android:name="io.flutter.app.FlutterApplication"
        android:label="myfavkpopapp_example"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- This keeps the window background of the activity showing
                 until Flutter renders its first frame. It can be removed if
                 there is no splash screen (such as the default splash screen
                 defined in @style/LaunchTheme). -->
            <meta-data
                android:name="io.flutter.app.android.SplashScreenUntilFirstFrame"
                android:value="true" />
            <meta-data
                    android:name="com.google.android.gms.ads.APPLICATION_ID"
                    android:value="ca-app-pub-[ADMOB ID]"/>
            <meta-data
                    android:name="com.google.android.gms.version"
                    android:value="@integer/google_play_services_version" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
    </application>

2 个答案:

答案 0 :(得分:1)

您需要在此处添加您的真实admob ID:

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-[ADMOB ID]"/>

答案 1 :(得分:0)

<meta-data
                android:name="com.google.android.gms.ads.APPLICATION_ID"
                android:value="ca-app-pub-[ADMOB ID]"/>

您将应用 ID 设置为 ca-app-pub-[ADMOB ID] 并添加互联网权限