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

Viewed 2523

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

6 Answers

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.

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.

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

Working for me. Just update the packages of both youtube_player_flutter and webview_flutter. After that use both flutter clean and flutter packages get commands to solve this issue.

I had the same issue using webview_flutter and youtube_player_flutter. I used the solution by @srinivasanrsp on Github. It works.

The problem: youtube_player_flutter uses the webview to play the videos from Youtube. so you are (unknowingly) trying to import and use the same package.

Solution:

  • Remove the webview_flutter package from the pubspec.yaml file
  • Use import 'package:webview_media/webview_flutter.dart' as your webview.; This works just fine.
Related