1
votes

After updating my flutter project when I was going to run the application in the android studio, I got the following error.

e: C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\fluttertoast-7.1.5\android\src\main\kotlin\io\github\ponnamkarthik\toast\fluttertoast\MethodCallHandlerImpl.kt: (16, 16): Redeclaration: MethodCallHandlerImpl
e: C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\fluttertoast-7.1.6\android\src\main\kotlin\io\github\ponnamkarthik\toast\fluttertoast\MethodCallHandlerImpl.kt: (17, 16): Redeclaration: MethodCallHandlerImpl

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':fluttertoast:compileDebugKotlin'.
> Compilation error. See log for more 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 52s
Exception: Gradle task assembleDebug failed with exit code 1

I tried following steps but I was not able to fix this.

  • pub get, pub upgrade

  • And here's my flutter doctor result

    "C:\Program Files\flutter\bin\flutter.bat" doctor --verbose [√] Flutter (Channel stable, 1.22.4, on Microsoft Windows [Version 10.0.19042.804], locale en-US) • Flutter version 1.22.4 at C:\Program Files\flutter • Framework revision 1aafb3a8b9 (3 months ago), 2020-11-13 09:59:28 -0800 • Engine revision 2c956a31c0 • Dart version 2.10.4

    [!] Android toolchain - develop for Android devices (Android SDK version 30.0.2) • Android SDK at C:/Users/user/AppData/Local/Android/Sdk • Platform android-30, build-tools 30.0.2 • ANDROID_HOME = C:/Users/user/AppData/Local/Android/Sdk • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01) X Android license status unknown. Run flutter doctor --android-licenses to accept the SDK licenses. See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.

    [!] Android Studio (version 4.1.0) • Android Studio at C:\Program Files\Android\Android Studio X Flutter plugin not installed; this adds Flutter specific functionality. X Dart plugin not installed; this adds Dart specific functionality. • Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)

    [!] VS Code (version 1.53.0) • VS Code at C:\Users\user\AppData\Local\Programs\Microsoft VS Code X Flutter extension not installed; install from https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter

    [√] Connected device (1 available) • sdk gphone x86 arm (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator)

    ! Doctor found issues in 3 categories. Process finished with exit code 0

How can I fix this issue?

3

3 Answers

2
votes

This was happened due to a pub cache conflict. The problem was fixed after executing the following command in the terminal.

  1. dart pub cache repair
  2. dart pub get
  3. dart pub upgrade
0
votes

I tried your solution but it does not work for me. My solution is update compileSdkVersion to 30 in my app/build.gradle.

0
votes

I got the same error. Tried updating compileSdkVersion. Didn't work for me. This solved my problem.

  1. pubspec.yaml -->> pub upgrade
  2. Change fluttertoast version to latest
  3. Pub get
  4. Run...