问题描述
我需要一些帮助,我正在尝试在Flutter应用程序中添加NativeAd,现在我可以毫无问题地显示BannerAd,但是在我的主要活动中配置NativeAd并运行该应用程序后,我得到了一个错误:
E/AndroidRuntime(26483): java.lang.RuntimeException: Unable to start activity ComponentInfo{site.shoppity/site.shoppity.MainActivity}: java.lang.IllegalStateException: Could not find a FirebaseAdMobPlugin instance. The plugin may have not been registered.
E/AndroidRuntime(26483): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:3477)
E/AndroidRuntime(26483): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3620)
E/AndroidRuntime(26483): at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
E/AndroidRuntime(26483): at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
E/AndroidRuntime(26483): at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
E/AndroidRuntime(26483): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2183)
E/AndroidRuntime(26483): at android.os.Handler.dispatchMessage(Handler.java:107)
E/AndroidRuntime(26483): at android.os.Looper.loop(Looper.java:241)
E/AndroidRuntime(26483): at android.app.ActivityThread.main(ActivityThread.java:7604)
E/AndroidRuntime(26483): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(26483): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(26483): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:941)
E/AndroidRuntime(26483): Caused by: java.lang.IllegalStateException: Could not find a FirebaseAdMobPlugin instance. The plugin may have not been registered.
E/AndroidRuntime(26483): at io.Flutter.plugins.firebaseadmob.FirebaseAdMobPlugin.registerNativeAdFactory(FirebaseAdMobPlugin.java:137)
E/AndroidRuntime(26483): at io.Flutter.plugins.firebaseadmob.FirebaseAdMobPlugin.registerNativeAdFactory(FirebaseAdMobPlugin.java:127)
E/AndroidRuntime(26483): at site.shoppity.MainActivity.configureFlutterEngine(MainActivity.kt:12)
E/AndroidRuntime(26483): at io.Flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:180)
E/AndroidRuntime(26483): at io.Flutter.embedding.android.FlutterActivity.onCreate(FlutterActivity.java:411)
E/AndroidRuntime(26483): at android.app.Activity.performCreate(Activity.java:7822)
E/AndroidRuntime(26483): at android.app.Activity.performCreate(Activity.java:7811)
E/AndroidRuntime(26483): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1328)
E/AndroidRuntime(26483): at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:3452)
E/AndroidRuntime(26483): ... 11 more
这是我的主要活动代码:
import io.Flutter.embedding.android.FlutterActivity;
import io.Flutter.embedding.engine.FlutterEngine;
import io.Flutter.plugins.firebaseadmob.FirebaseAdMobPlugin;
import io.Flutter.plugins.firebaseadmob.FirebaseAdMobPlugin.NativeAdFactory;
class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(FlutterEngine: FlutterEngine) {
val factory: NativeAdFactory = MyNativeAdFactory(getLayoutInflater());
FirebaseAdMobPlugin.registerNativeAdFactory(FlutterEngine,"myAdFactory",factory);
}
override fun cleanUpFlutterEngine(FlutterEngine: FlutterEngine) {
FirebaseAdMobPlugin.unregisterNativeAdFactory(FlutterEngine,"myAdFactory");
}
}
我尝试在主Activity中注册FirebaseAdMobPlugin,但该应用程序的其他插件停止工作
FlutterEngine.getPlugins().add(new FirebaseAdMobPlugin());
在android文件夹中,我看到了一个名为“ GeneratedpluginRegistrant”的类,用于注册插件:
* plugins that support the Android platform.
*/
@Keep
public final class GeneratedpluginRegistrant {
public static void registerWith(@NonNull FlutterEngine FlutterEngine) {
ShimPluginRegistry shimPluginRegistry = new ShimPluginRegistry(FlutterEngine);
com.noeatsleepdev.geoFlutterfire.GeoFlutterfirePlugin.registerWith(shimPluginRegistry.registrarFor("com.noeatsleepdev.geoFlutterfire.GeoFlutterfirePlugin"));
FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebase.cloudfirestore.CloudFirestorePlugin());
io.Flutter.plugins.firebase.cloudfunctions.CloudFunctionsPlugin.registerWith(shimPluginRegistry.registrarFor("io.Flutter.plugins.firebase.cloudfunctions.CloudFunctionsPlugin"));
com.notrait.deviceid.deviceidPlugin.registerWith(shimPluginRegistry.registrarFor("com.notrait.deviceid.deviceidPlugin"));
de.esys.esysFluttershare.EsysFlutterSharePlugin.registerWith(shimPluginRegistry.registrarFor("de.esys.esysFluttershare.EsysFlutterSharePlugin"));
**FlutterEngine.getPlugins().add(new io.Flutter.plugins.firebaseadmob.FirebaseAdMobPlugin());**
...
一些推荐?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)