Closed BrianTum closed 2 years ago
Hi @BrianTum, Thanks for filing the issue.
I tried running the sample app and I was able to build and run the app using the google_mobile_ads: ^ 1.0.0
on the stable channel. Please share the minimal and complete code sample to investigate further.
Must to add GeneratedPluginRegistrant.registerWith(flutterEngine); before nativeadfactoryy:
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine); <-----
val factory: NativeAdFactory = NativeAdFactoryExample(layoutInflater)
GoogleMobileAdsPlugin.registerNativeAdFactory(flutterEngine, "adFactoryExample", factory)
Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this bug for now. If you find this problem please file a new issue with the same description, what happens, logs and the output of 'flutter doctor -v'. All system setups can be slightly different so it's always better to open new issues and reference the related ones. Thanks for your contribution.
Plugin Version : google_mobile_ads: ^1.0.0
Steps to Reproduce
Expected results: Just wanted to run and launch the app
Actual results: But app crashed immediately it launches with an error GoogleMobileAdsPlugin instance not found -->
Logs
However I have initialized the mobileads SDK in the main.dart ``` void main() async { WidgetsFlutterBinding.ensureInitialized(); await Firebase.initializeApp(); await MobileAds.instance.initialize(); Directory document = await getApplicationDocumentsDirectory(); Hive.init(document.path); await Hive.openBox("storyCACHE"); runApp(MyApp()); } ``` Running your application with `flutter run --verbose`. ``` [+5301 ms] E/AndroidRuntime(23382): FATAL EXCEPTION: main [ ] E/AndroidRuntime(23382): Process: com.picmoni, PID: 23382 [ ] E/AndroidRuntime(23382): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.picmoni/com.picmoni.MainActivity}: java.lang.IllegalStateException: Could not find a GoogleMobileAdsPlugin instance. The plugin may have not been registered. [ +1 ms] E/AndroidRuntime(23382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3827) [ ] E/AndroidRuntime(23382): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:4003) [ ] E/AndroidRuntime(23382): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:85) [ ] E/AndroidRuntime(23382): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) [ ] E/AndroidRuntime(23382): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) [ ] E/AndroidRuntime(23382): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2317) [ ] E/AndroidRuntime(23382): at android.os.Handler.dispatchMessage(Handler.java:106) [ +2 ms] E/AndroidRuntime(23382): at android.os.Looper.loop(Looper.java:246) [ +5 ms] E/AndroidRuntime(23382): at android.app.ActivityThread.main(ActivityThread.java:8595) [ ] E/AndroidRuntime(23382): at java.lang.reflect.Method.invoke(Native Method) [ ] E/AndroidRuntime(23382): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:602) [ ] E/AndroidRuntime(23382): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1130) [ +1 ms] E/AndroidRuntime(23382): Caused by: java.lang.IllegalStateException: Could not find a GoogleMobileAdsPlugin instance. The plugin may have not been registered. [ +1 ms] E/AndroidRuntime(23382): at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.registerNativeAdFactory(GoogleMobileAdsPlugin.java:176) [ ] E/AndroidRuntime(23382): at io.flutter.plugins.googlemobileads.GoogleMobileAdsPlugin.registerNativeAdFactory(GoogleMobileAdsPlugin.java:123) [ ] E/AndroidRuntime(23382): at com.picmoni.MainActivity.configureFlutterEngine(MainActivity.java:13) [ +2 ms] E/AndroidRuntime(23382): at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:187) [ ] E/AndroidRuntime(23382): at io.flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:430) [ ] E/AndroidRuntime(23382): at android.app.Activity.performCreate(Activity.java:8207) [ ] E/AndroidRuntime(23382): at android.app.Activity.performCreate(Activity.java:8191) [ ] E/AndroidRuntime(23382): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1309) [ +1 ms] E/AndroidRuntime(23382): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3800) [ ] E/AndroidRuntime(23382): ... 11 more ``` Run `flutter analyze` ``` No issues found! (ran in 121.1s) ``` Output of running `flutter doctor -v` ``` [√] Flutter (Channel stable, 2.5.3, on Microsoft Windows [Version 10.0.19043.1348], locale en-US) • Flutter version 2.5.3 at C:\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 18116933e7 (5 weeks ago), 2021-10-15 10:46:35 -0700 • Engine revision d3ea636dc5 • Dart version 2.14.4 [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at C:\Users\user\AppData\Local\Android\sdk • Platform android-31, build-tools 31.0.0 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Users\user\AppData\Local\Google\Chrome\Application\chrome.exe [√] Android Studio (version 2020.3) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [√] VS Code (version 1.62.2) • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.28.0 [√] Connected device (3 available) • SM M625F (mobile) • 192.168.8.115:5555 • android-arm64 • Android 11 (API 30) • Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69 • Edge (web) • edge • web-javascript • Microsoft Edge 92.0.902.78 • No issues found! ```