Error in R8 Program type already present, when compiling the app

2,368

Solution 1

As the message indicate the class io.flutter.plugins.webviewflutter.BuildConfig is present twice in the input. You will need to track down the two dependencies which have this class.

You can use

./gradlew app:dependencies

and

./gradlew app:androidDependencies

to get information on all dependencies. Then you need to figure out how to avoid one of these dependencies.

Solution 2

Found out the answer, you can remove the webview_flutter from your pubspec.yaml, so you just use youtube_player_flutter on your pubspec.yaml. You still can use the webview with all the functionality from webview_flutter with import 'package:webview_media/webview_flutter.dart'; on the dart file that using the webview.

Solution 3

I got this problem cause youtube_player_flutter and flutter_html were using the same dependency flutter_webview.

I used this and work like a charm

  • flutter_html: ^1.0.0
  • webview_flutter: ^0.3.19+5
  • youtube_player_flutter: 6.0.3+2
Share:
2,368
Rogers Marques
Author by

Rogers Marques

Updated on December 14, 2022

Comments

  • Rogers Marques
    Rogers Marques over 1 year

    I'm trying to compile the APK for Flutter, but I'm getting an error in r8. I already have other apps in Flutter, but I never had a problem compiling and making the tests with them. I realize that the problem is the WebView library because when I remove it from the pubspec the app compiles. But I can't discard the use of the WebView at the moment, it is important for the app. The strange thing is that I can debug the app on the device.

    I've tried several solutions like the ones below:

    gradlew clean in project-flutter / android
    flutter clean
    

    And the following steps:

    • Updated to the latest version of webview dependency in the pub spec.
    • I have already switched to the flutter master channel.
    • Also performed the flutter upgrade but nothing solves the problem.

    I get the following error:

    R8: Program type already present: io.flutter.plugins.webviewflutter.BuildConfig

    FAILURE: Build failed with an exception.

    What went wrong:

    Execution failed for task ':app:transformClassesAndResourcesWithR8ForRelease'. com.android.tools.r8.CompilationFailedException: Compilation failed to complete

    ref r8: https://developer.android.com/studio/build/shrink-code?hl=pt-br

    • Ameer
      Ameer over 4 years
      I m also facing the similar issue with webview plugin with error as D8: Program type already present: io.flutter.plugins.webviewflutter.BuildConfig.
    • aswin darma
      aswin darma about 4 years
      Actually I have the exact same problem when building the APK for my project, but when running it on my test device, it works. Found out I'm using youtube_player_flutter plugin which if I delete it, the build process will work fine, still don't know why the latest version of flutter have so many dependencies that can't work together (this is not my first problem of can't use some dependencies together)
  • aswin darma
    aswin darma about 4 years
    is there another way to keep using the plugin/dependencies?
  • Jaimil Patel
    Jaimil Patel about 4 years
    Answers that contains only links will be delete in future so please post your answers with code and its explanation.