firebase / flutterfire

🔥 A collection of Firebase plugins for Flutter apps.
https://firebase.google.com/docs/flutter/setup
BSD 3-Clause "New" or "Revised" License
8.68k stars 3.97k forks source link

AdMob InterstitialAd Fail to fetch AdActivity theme #1183

Closed kroikie closed 5 years ago

kroikie commented 5 years ago

Steps to Reproduce

  1. I have successfully implemented the BannerAd but got errors when try to show InterstitialAd, here are the codes:

main.dart:

import 'package:firebase_admob/firebase_admob.dart';

Future<void> main() async {
  FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
  ...
}

page.dart:

class _PageState extends State<Page> {

  static const MobileAdTargetingInfo targetingInfo = MobileAdTargetingInfo(
    testDevices: testDevice != null ? <String>[testDevice] : null,
    keywords: <String>['foo', 'bar'],
    contentUrl: 'http://foo.com/bar.html',
    childDirected: true,
    nonPersonalizedAds: true,
  );

  InterstitialAd _interstitialAd;

  InterstitialAd createInterstitialAd() {
    return InterstitialAd(
      adUnitId: InterstitialAd.testAdUnitId,
      targetingInfo: targetingInfo,
      listener: (MobileAdEvent event) {
        print("InterstitialAd event $event");
        if (event == MobileAdEvent.failedToLoad) {
          _interstitialAd.load();
        } else if (event == MobileAdEvent.loaded) {
          print('interstitialAd show');
          _interstitialAd.show();
        }
      },
    );
  }

  @override
  void initState() {
    super.initState();
    _interstitialAd = createInterstitialAd()
      ..load()
      ..show();
  }

  @override
  void dispose() {
    _interstitialAd?.dispose();
    super.dispose();
  }
}

AndroidManifest.xml:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.wingtech.quicklearnersdictionary">

    <!-- The INTERNET permission is required for development. Specifically,
         flutter needs it to communicate with the running application
         to allow setting breakpoints, to provide hot reload, etc.
    -->
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.CAMERA" />
    <uses-permission android:name="android.permission.FLASHLIGHT" />

    <uses-feature android:name="android.hardware.camera" />
    <uses-feature android:name="android.hardware.camera.autofocus" />
    <uses-feature android:name="android.hardware.camera.flash" />

    <!-- io.flutter.app.FlutterApplication is an android.app.Application that
         calls FlutterMain.startInitialization(this); in its onCreate method.
         In most cases you can leave this as-is, but you if you want to provide
         additional functionality it is fine to subclass or reimplement
         FlutterApplication and put your custom class here. -->
    <application
        android:name="io.flutter.app.FlutterApplication"
        android:icon="@mipmap/ic_launcher"
        android:label="Quick Learner's Dictionary">
        <meta-data
            android:name="com.google.firebase.ml.vision.DEPENDENCIES"
            android:value="ocr" />
        <meta-data
            android:name="com.google.android.gms.ads.APPLICATION_ID"
            android:value="ca-app-pub-3940256099942544~3347511713"/>
        <activity
            android:name=".MainActivity"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|layoutDirection|fontScale|screenLayout|density"
            android:hardwareAccelerated="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            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" />
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

Logs

[ +204 ms] W/Ads     (19033): #004 The webview is destroyed. Ignoring action.
[  +19 ms] I/chatty  (19033): uid=10242(com.wingtech.quicklearnersdictionary) identical 1 line
[        ] W/Ads     (19033): #004 The webview is destroyed. Ignoring action.
[        ] W/Ads     (19033): #004 The webview is destroyed. Ignoring action.
[        ] W/Ads     (19033): #004 The webview is destroyed. Ignoring action.
[  +49 ms] D/DynamitePackage(19033): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
[   +9 ms] I/Ads     (19033): Use AdRequest.Builder.addTestDevice("4BA937CAFB7EC3E15A0A7D82CFE96A7D") to get test ads on this device.
[  +42 ms] D/DynamitePackage(19033): Instantiating com.google.android.gms.ads.ChimeraAdManagerCreatorImpl
[   +6 ms] I/Ads     (19033): Use AdRequest.Builder.addTestDevice("4BA937CAFB7EC3E15A0A7D82CFE96A7D") to get test ads on this device.
[  +19 ms] W/Ads     (19033): Fail to fetch AdActivity theme
[        ] I/Ads     (19033): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
[   +4 ms] W/System  (19033): A resource failed to call release. 
[  +20 ms] W/Ads     (19033): Fail to fetch AdActivity theme
[        ] I/Ads     (19033): Please set theme of AdActivity to @android:style/Theme.Translucent to enable transparent background interstitial ad.
[   +6 ms] W/Ads     (19033): Not retrying to fetch app settings
[ +737 ms] I/flutter (19033): application MobileAdEvent.loaded
[ +140 ms] I/flutter (19033): InterstitialAd event MobileAdEvent.loaded
[        ] I/flutter (19033): interstitialAd show

Try to add

<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

to AndroidManifest.xml but doesn't work!

flutter analyze:

Analyzing quick_learners_dictionary...                                  
No issues found! (ran in 35.7s)
[✓] Flutter (Channel stable, v1.2.1, on Linux, locale en_US.UTF-8)
    • Flutter version 1.2.1 at /home/zhangyuzhou/flutter
    • Framework revision 8661d8aecd (4 weeks ago), 2019-02-14 19:19:53 -0800
    • Engine revision 3757390fa4
    • Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)

[✓] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
    • Android SDK at /home/zhangyuzhou/Android/Sdk
    • Android NDK location not configured (optional; useful for native profiling support)
    • Platform android-28, build-tools 28.0.3
    • Java binary at: /home/zhangyuzhou/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
    • All Android licenses accepted.

[✓] Android Studio (version 3.3)
    • Android Studio at /home/zhangyuzhou/android-studio
    • Flutter plugin version 33.4.1
    • Dart plugin version 182.5215
    • Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)

[!] IntelliJ IDEA Community Edition (version 2018.1)
    • IntelliJ at /home/zhangyuzhou/Downloads/idea-IC-181.4892.42
    ✗ Flutter plugin not installed; this adds Flutter specific functionality.
    ✗ Dart plugin not installed; this adds Dart specific functionality.
    • For information about installing plugins, see
      https://flutter.io/intellij-setup/#installing-the-plugins

[!] VS Code (version 1.32.3)
    • VS Code at /usr/share/code
    ✗ Flutter extension not installed; install from
      https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

[✓] Connected device (1 available)
    • Pixel 2 XL • 805KPYR1822994 • android-arm64 • Android 9 (API 28)

! Doctor found issues in 2 categories.
brahim-dev commented 4 years ago

this application pubished on google play