googleads/googleads-mobile-flutter

Native Ad Load crashes when using FlutterFragmentActivity

danijorda1 opened this issue · 2 comments

Step 0: Are you in the right place?

  • For general technical questions, or help with project-specific issues like setting up ads in
    your app, reach out to our support team on the
    Developer Forum.

  • For assistance with your AdMob account, reach out to
    AdMob Support.

  • For feedback on our documentation,
    send your feedback by pressing the Send Feedback button at the top right of the
    documentation page you are on.

  • For issues related to the code in this repository, continue filing this GitHub issue.

  • Once you've read this section and determined that your issue is appropriate for
    this repository, please delete this section.


[REQUIRED] Step 1: Describe your environment

Plugin Version

5.1.0

[REQUIRED] Step 2: Describe the problem

Native Ad Load crashes when using FlutterFragmentActivity in MainActivity.kt

Steps to Reproduce

  1. Create a project
  2. Add google_mobile_ads
  3. Modify MainActivity.kt (or .java) and change the default class to:
    class MainActivity: FlutterFragmentActivity() {
  4. try to load a test Native add in the flutter main activity:
    nativeAd = NativeAd(
    adUnitId: 'ca-app-pub-3940256099942544/2247696110',
    listener: NativeAdListener(), request: AdRequest(),
    nativeTemplateStyle: NativeTemplateStyle(templateType:TemplateType.medium)
    );
    nativeAd!.load();
  5. Run application.
  1. Run flutter create bug.
  2. Update the files as follows: ...
  3. ...

Expected results:
Native add is loaded. No further issues.
Actual results:
: FATAL EXCEPTION: main
E/AndroidRuntime( 579): Process: XXXXX, PID: 579
E/AndroidRuntime( 579): android.view.InflateException: Binary XML file line #7 in es.lotofintech.winr:layout/medium_template_view_layout: Binary XML file line #7 in es.lotofintech.winr:layout/medium_template_view_layout: Error inflating class com.google.android.ads.nativetemplates.TemplateView
E/AndroidRuntime( 579): Caused by: android.view.InflateException: Binary XML file line #7 in es.lotofintech.winr:layout/medium_template_view_layout: Error inflating class com.google.android.ads.nativetemplates.TemplateView
E/AndroidRuntime( 579): Caused by: java.lang.IllegalStateException: LifecycleOwner es.lotofintech.winr.MainActivity@72e1f36 is attempting to register while current state is RESUMED. LifecycleOwners must call register before they are STARTED.
E/AndroidRuntime( 579): at androidx.activity.result.ActivityResultRegistry.register(ActivityResultRegistry.kt:93)
E/AndroidRuntime( 579): at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.kt:828)
E/AndroidRuntime( 579): at androidx.activity.ComponentActivity.registerForActivityResult(ComponentActivity.kt:837)
E/AndroidRuntime( 579): at es.lotofintech.winr.MainActivity.getStartForResult(MainActivity.kt:227)
E/AndroidRuntime( 579): at es.lotofintech.winr.MainActivity.onCreateView(MainActivity.kt:261)

Logs

Hi @danijorda1 can you provide a minimum reproducible sample of the crash you are experiencing for us to take a closer look?

Thanks!

Closing due to inactivity