flutter_barcode_scanner: com.package.MainActivity cannot be cast to io.flutter.embedding.android.FlutterActivity

Because of some of my Plugins, i have to use FlutterFragmentActivity instead of FlutterActivity.

Unfortunately the Plugin is not working then.

Error:

E/AndroidRuntime(18103): java.lang.ClassCastException: de.fitasy.MainActivity cannot be cast to io.flutter.embedding.android.FlutterActivity
E/AndroidRuntime(18103): 	at com.amolg.flutterbarcodescanner.FlutterBarcodeScannerPlugin.createPluginSetup(FlutterBarcodeScannerPlugin.java:248)
E/AndroidRuntime(18103): 	at com.amolg.flutterbarcodescanner.FlutterBarcodeScannerPlugin.onAttachedToActivity(FlutterBarcodeScannerPlugin.java:275)
E/AndroidRuntime(18103): 	at io.flutter.embedding.engine.FlutterEnginePluginRegistry.add(FlutterEnginePluginRegistry.java:143)
E/AndroidRuntime(18103): 	at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:26)
E/AndroidRuntime(18103): 	at de.fitasy.MainActivity.configureFlutterEngine(MainActivity.kt:10)
E/AndroidRuntime(18103): 	at io.flutter.embedding.android.FlutterFragment.configureFlutterEngine(FlutterFragment.java:950)
E/AndroidRuntime(18103): 	at io.flutter.embedding.android.FlutterActivityAndFragmentDelegate.onAttach(FlutterActivityAndFragmentDelegate.java:181)
E/AndroidRuntime(18103): 	at io.flutter.embedding.android.FlutterFragment.onAttach(FlutterFragment.java:582)
E/AndroidRuntime(18103): 	at androidx.fragment.app.Fragment.performAttach(Fragment.java:2574)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentManagerImpl.moveToState(FragmentManagerImpl.java:828)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentTransition.addToFirstInLastOut(FragmentTransition.java:1197)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentTransition.calculateFragments(FragmentTransition.java:1080)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentTransition.startTransitions(FragmentTransition.java:119)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentManagerImpl.executeOpsTogether(FragmentManagerImpl.java:1866)
E/AndroidRuntime(18103): 	at androidx.fragment.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManagerImpl.java:1824)

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 11
  • Comments: 16

Commits related to this issue

Most upvoted comments

In file FlutterBarcodeScannerPlugin.java

I’ve modified all reference to FlutterActivity to FlutterFragmentActivity and now it works.

This is a workaround that works for me.

but where is this file?? Thanks

.pub-cache/hosted/pub.dartlang.org/flutter_barcode_scanner-2.0.0/android/src/main/java/com/amolg/flutterbarcodescanner