I had an old project kind off like a POC 2-3 years old in flutter, Now when I try to run it on the latest version I get the following error:
On Flutter Run:
/Users/jci/Documents/Projects/Flutter/dicee/android/app/src/main/java/co/appbrewery/dicee/MainActivity.java:11: error: incompatible types: MainActivity cannot be converted to FlutterEngine
GeneratedPluginRegistrant.registerWith(this);
^
Note: /Users/jci/Documents/Projects/Flutter/dicee/android/app/src/main/java/co/appbrewery/dicee/MainActivity.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 21s
Exception: Gradle task assembleDebug failed with exit code 1
Flutter Run -v:
[ +1 ms] /Users/jci/Documents/Projects/Flutter/dicee-flutter/android/app/src/main/java/co/appbrewery/dicee/MainActivity.java:11: error: incompatible types:
MainActivity cannot be converted to FlutterEngine
[ +2 ms] GeneratedPluginRegistrant.registerWith(this);
[ ] ^
[ ] Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
[ ] 1 error
[ ] FAILURE: Build failed with an exception.
[ ] * What went wrong:
[ ] Execution failed for task ':app:compileDebugJavaWithJavac'.
[ ] > Compilation failed; see the compiler error output for details.
[ ] * Try:
[ ] Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full
insights.
[ ] * Get more help at https://help.gradle.org
[ ] BUILD FAILED in 3s
[ ] Deprecated Gradle features were used in this build, making it incompatible with Gradle 7.0.
[ ] Use '--warning-mode all' to show the individual deprecation warnings.
[ ] See https://docs.gradle.org/6.7.1/userguide/command_line_interface.html#sec:command_line_warnings
[ ] 17 actionable tasks: 5 executed, 12 up-to-date
[ +379 ms] Running Gradle task 'assembleDebug'... (completed in 4.3s)
[+2421 ms] Exception: Gradle task assembleDebug failed with exit code 1
[ +1 ms] "flutter run" took 21,908ms.
[ +3 ms]
#0 throwToolExit (package:flutter_tools/src/base/common.dart:10:3)
#1 RunCommand.runCommand (package:flutter_tools/src/commands/run.dart:699:9)
<asynchronous suspension>
#2 FlutterCommand.run.<anonymous closure> (package:flutter_tools/src/runner/flutter_command.dart:1183:27)
<asynchronous suspension>
#3 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#4 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#5 FlutterCommandRunner.runCommand.<anonymous closure> (package:flutter_tools/src/runner/flutter_command_runner.dart:281:9)
<asynchronous suspension>
#6 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#7 FlutterCommandRunner.runCommand (package:flutter_tools/src/runner/flutter_command_runner.dart:229:5)
<asynchronous suspension>
#8 run.<anonymous closure>.<anonymous closure> (package:flutter_tools/runner.dart:62:9)
<asynchronous suspension>
#9 AppContext.run.<anonymous closure> (package:flutter_tools/src/base/context.dart:150:19)
<asynchronous suspension>
#10 main (package:flutter_tools/executable.dart:94:3)
<asynchronous suspension>
Not quite certain if it's a single error or multiple, my guess is it has something to do with my gradle any help whatsoever is appreciated.
It's been a while since I have not checked flutter so I am not sure what the error means...
After putting in some hours into this I realized that the issue was with my Activity having the old flutter engine config code, to fix this all i had to do was go from this:
import android.os.Bundle;
import io.flutter.app.FlutterActivity;
import io.flutter.plugins.GeneratedPluginRegistrant;
public class MainActivity extends FlutterActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GeneratedPluginRegistrant.registerWith(this);
}
}
where it was registering PluginRegistrant to that:
import io.flutter.embedding.android.FlutterActivity;
public class MainActivity extends FlutterActivity {
}
More information in the Flutter Github Upgradation document