question-mark

Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Issue Description

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)

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:11
  • Comments:16

github_iconTop GitHub Comments

26reactions
koyadoviccommented, Oct 22, 2020

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.

2reactions
fmancusomilitecommented, Feb 16, 2022

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

com.deliveryrunner.vendor.MainActivity cannot be cast to ...
and it worked fine back then. Here is the old Application file : package com.deliveryrunner.vendor; import io.flutter.app.
Read more >
Supporting the new Android plugins APIs | Flutter
The following instructions outline the steps for supporting the new API: ... package io.flutter.plugins.firebasecoreexample; import io.flutter.embedding.android.
Read more >
Fix Application crash Error “android.app.Application cannot be ...
FATAL EXCEPTION, Fix Application crash Error “ android.app.Application cannot be cast to”#FataException #RuntimeException #JavaException.
Read more >
Native | Flutter - Google Developers
package my.app.path; import io.flutter.embedding.android.FlutterActivity; import io.flutter.embedding.engine.FlutterEngine;
Read more >
Firebase – java.lang.RuntimeException - flutter - iTecNote
RuntimeException: Unable to instantiate activity in Flutter ... MainActivity cannot be cast to android.app. ... import 'package:flutter/material.dart'; ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found