flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

Build error with latest flutter/agp versions

Open holzgeist opened this issue 1 year ago • 26 comments

  • [x] I have read the Getting Started section
  • [x] I have already searched for the same problem

Environment

Technology Version
Flutter version 3.22
Plugin version 1.0.13
Android version 14
iOS version --
macOS version --
Xcode version --
Google Chrome version --
Android Gradle Plugin 8.4.0

Device information: irrelevant, as this is a build error

Description

Expected behavior:

Be able to compile an app on Android using this plugin with obfuscation/minification

Current behavior:

Build error during minification:

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in .../build/flutter_inappwebview_android/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class android.window.BackEvent (referenced from: void io.flutter.embedding.android.FlutterActivity.startBackGesture(android.window.BackEvent) and 3 other contexts)

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':flutter_inappwebview_android:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

Steps to reproduce

  1. Depend on flutter_inappwebview
  2. Upgrade to latest flutter/AGP/...
  3. Do a release build with minification (e.g. flutter build apk --obfuscate --split-debug-info /tmp/debug-info. Alternatively, skip --obfuscate --split-debug-info ... and set minifyEnabled true in android/app/build.gradle

holzgeist avatar May 14 '24 09:05 holzgeist

👋 @holzgeist

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

github-actions[bot] avatar May 14 '24 09:05 github-actions[bot]

It would be great if the according PR could be merged quickly, as this currently blocks us (and probably other devs as well) from building releases, and downgrading to an earlier version is quite cumbersome as the API has changed in between.

komaxx avatar May 15 '24 11:05 komaxx

It would be great if the according PR could be merged quickly, as this currently blocks us (and probably other devs as well) from building releases, and downgrading to an earlier version is quite cumbersome as the API has changed in between.

Any luck pointing your dependency to the pull request? it doesn't work on my side

Augustinekan avatar May 15 '24 12:05 Augustinekan

Ah, good point! Got it to run with:

dependency_overrides:
  # TODO: Recheck once flutter_inappwebview version >6.0.0 is released
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

komaxx avatar May 15 '24 12:05 komaxx

I closed the according PR because it was a duplicate of #2102

holzgeist avatar May 16 '24 05:05 holzgeist

Ah, good point! Got it to run with:

dependency_overrides:
  # TODO: Recheck once flutter_inappwebview version >6.0.0 is released
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

You saved my deploy today. Thank you so much!

flechajm avatar May 16 '24 14:05 flechajm

Still having an issue even afetr depending on holzgeist repo

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/username/Desktop/projectname/build/app/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class com.google.j2objc.annotations.ReflectionSupport$Level (referenced from: com.google.common.util.concurrent.AbstractFuture)
Missing class com.google.j2objc.annotations.ReflectionSupport (referenced from: com.google.common.util.concurrent.AbstractFuture)
Missing class com.google.j2objc.annotations.RetainedWith (referenced from: com.google.common.collect.ImmutableSet com.google.common.collect.ImmutableMap.entrySet and 3 other contexts)

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

specOper99 avatar May 19 '24 10:05 specOper99

Still having an issue even afetr depending on holzgeist repo

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/username/Desktop/projectname/build/app/outputs/mapping/release/missing_rules.txt.
ERROR: R8: Missing class com.google.j2objc.annotations.ReflectionSupport$Level (referenced from: com.google.common.util.concurrent.AbstractFuture)
Missing class com.google.j2objc.annotations.ReflectionSupport (referenced from: com.google.common.util.concurrent.AbstractFuture)
Missing class com.google.j2objc.annotations.RetainedWith (referenced from: com.google.common.collect.ImmutableSet com.google.common.collect.ImmutableMap.entrySet and 3 other contexts)

FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':app:minifyReleaseWithR8'.
> A failure occurred while executing com.android.build.gradle.internal.tasks.R8Task$R8Runnable
   > Compilation failed to complete

@specOper99 - looks like your issue is not linked to flutter_inappwebview, but that fact that your proguard.pro file is not there.
check if you have the proguard-rules.pro file in your project (android/app/). if not create one and then add the following lines

-ignorewarnings -keep class * { public private *; }

Yohan-J avatar May 20 '24 12:05 Yohan-J

@Yohan-J You have an issue with Proguard but it's a different one. check the actual issue here.

  • Actual issue is about the R8: Missing class android.window.BackEvent and your issue is R8: Missing class com.google.j2objc.annotations.ReflectionSupport$Level that is from a different thing.

nayanbabariya avatar May 20 '24 13:05 nayanbabariya

@nayanbabariya yes, this wasn't my issue, but i was also replying to the comment above mine, stating that his issue was something else.

Yohan-J avatar May 20 '24 13:05 Yohan-J

@Yohan-J Okay. but the mentioned issue is from the flutter_inappwebview plugin.

nayanbabariya avatar May 20 '24 13:05 nayanbabariya

@Yohan-J Thank you for your answer. Actually I noticed that lately (before few hours) that the problem is not related to flutter_inappwebview but it is related to awesome_notification if somebody is having it then can try to downgrade in order to be able to build cause whenever I try to ignore the warns it never changes its behaviour.

specOper99 avatar May 20 '24 17:05 specOper99

In my case, it seems the issue was caused by youtube_player_flutter that depends on flutter_inappwebview

max-anders avatar Jun 13 '24 13:06 max-anders

https://github.com/holzgeist/flutter_inappwebview

For Flutter project this is :

flutter_inappwebview: git: url: https://github.com/holzgeist/flutter_inappwebview.git path: flutter_inappwebview ref: fix-proguard-rules

In Flutter still get an error : Error: Type 'PlatformWebViewEnvironmentCreationParams' not found. required PlatformWebViewEnvironmentCreationParams params,

It seems that this upgraded package version with

'-dontwarn android.window.BackEvent'

added to Proguard causes following unexpected behaviour when running 'pub get' : Folder 'webview_environment' is removed from package

'https://github.com/pichillilorenzo/flutter_inappwebview/tree/master/flutter_inappwebview_platform_interface/lib/src'

. This causes missing classes when running Flutter project

This fix of https://github.com/MobileEasternts/flutter_inappwebview/tree/master is more complete and the branch master has the correction done which solves this issue

flutter_inappwebview: git: url: https://github.com/MobileEasternts/flutter_inappwebview.git path: flutter_inappwebview

davemg3 avatar Jun 15 '24 12:06 davemg3

the same here

toshiossada avatar Jun 19 '24 23:06 toshiossada

the same here. but, I solved it.

my error code

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/jeonglockpark/Desktop/work/daopass/daopass/build/flutter_inappwebview_android/outputs/mapping/release/missing_rules.txt.

Add 1

dependency_overrides:
  # TODO: Recheck once flutter_inappwebview version >6.0.0 is released
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

Add 2

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.j2objc.annotations.ReflectionSupport$Level
-dontwarn com.google.j2objc.annotations.ReflectionSupport
-dontwarn com.google.j2objc.annotations.RetainedWith

The build was successful with the two additional methods above. Hopefully the package will be updated normally soon.

Thanks a lot.

ttb-inc avatar Jun 20 '24 06:06 ttb-inc

the same here. but, I solved it.

my error code

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/jeonglockpark/Desktop/work/daopass/daopass/build/flutter_inappwebview_android/outputs/mapping/release/missing_rules.txt.

Add 1

dependency_overrides:
  # TODO: Recheck once flutter_inappwebview version >6.0.0 is released
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

Add 2

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.j2objc.annotations.ReflectionSupport$Level
-dontwarn com.google.j2objc.annotations.ReflectionSupport
-dontwarn com.google.j2objc.annotations.RetainedWith

The build was successful with the two additional methods above. Hopefully the package will be updated normally soon.

Thanks a lot.

Sorry, where am i putting this add, which file, Gradle or proguard?

AcuitySoftwareDev avatar Jul 01 '24 14:07 AcuitySoftwareDev

the same here. but, I solved it. my error code

Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/jeonglockpark/Desktop/work/daopass/daopass/build/flutter_inappwebview_android/outputs/mapping/release/missing_rules.txt.

Add 1

dependency_overrides:
  # TODO: Recheck once flutter_inappwebview version >6.0.0 is released
  flutter_inappwebview_android:
    git:
      url: https://github.com/holzgeist/flutter_inappwebview
      path: flutter_inappwebview_android
      ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

Add 2

# Please add these rules to your existing keep rules in order to suppress warnings.
# This is generated automatically by the Android Gradle plugin.
-dontwarn com.google.j2objc.annotations.ReflectionSupport$Level
-dontwarn com.google.j2objc.annotations.ReflectionSupport
-dontwarn com.google.j2objc.annotations.RetainedWith

The build was successful with the two additional methods above. Hopefully the package will be updated normally soon. Thanks a lot.

Sorry, where am i putting this add, which file, Gradle or proguard?

The first add goes to your pubspec.yaml file. Just add that below your dependencies block if you don't have any dependency_overrides yet. This tells the build pipeline to not use the real dependency but instead the one defined as override (a specific commit in a different repo).

The second one is not required in my setup, so you might not need it either. But if you do, this goes to the proguard-rules.pro file in your project's android/app folder.

komaxx avatar Jul 01 '24 14:07 komaxx

Noted with thanks, let me do that and build.

On Wed, Jul 3, 2024, 15:59 Sergio Molchanovsky @.***> wrote:

Ah, good point! Got it to run with:

dependency_overrides:

TODO: Recheck once flutter_inappwebview version >6.0.0 is released

flutter_inappwebview_android: git: url: https://github.com/holzgeist/flutter_inappwebview path: flutter_inappwebview_android ref: d89b1d32638b49dfc58c4b7c84153be0c269d057

After I added dependency_overrides, my apk size increased from 60 Mb to almost 110 Mb! Seems like you turned off some Proguard rules, and some unneeded stuff got into the assembly.

— Reply to this email directly, view it on GitHub https://github.com/pichillilorenzo/flutter_inappwebview/issues/2139#issuecomment-2206165151, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMS3LJIU4U3FGOGHOXJFWS3ZKP7TBAVCNFSM6AAAAABHV2CYFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMBWGE3DKMJVGE . You are receiving this because you commented.Message ID: @.***>

AcuitySoftwareDev avatar Jul 05 '24 08:07 AcuitySoftwareDev

I'm still sitting on a flutter_inappwebview 5.8, and we managed to remove this R8 error by adding the following line in the beginning of the android/build.gradle script:

project.gradle.startParameter.excludedTaskNames.add(":flutter_inappwebview:minifyReleaseWithR8")

I hope it will help to someone.

subzero911 avatar Jul 05 '24 20:07 subzero911

I'm still sitting on a flutter_inappwebview 5.8, and we managed to remove this R8 error by adding the following line in the beginning of the android/build.gradle script:

project.gradle.startParameter.excludedTaskNames.add(":flutter_inappwebview:minifyReleaseWithR8")

I hope it will help to someone.

This really helps

kevinzhow avatar Jul 21 '24 11:07 kevinzhow

We tried @subzero911 's fix (which seems better than referencing a PR branch) but did not work for our app, because when building from clean repo, skipping the minification task caused other tasks to fail because they weren't finding the expected output (the jar file).

This is an evolution of that fix, which properly disables minification instead of skipping the task, and for us it works even when building from scratch. Add this in the android/build.gradle file:

subprojects {
    afterEvaluate {
        if (it.name == "flutter_inappwebview_android") {
            it.android.buildTypes.release.minifyEnabled = false
        }
    }
}

If your file already has a subprojects / afterEvaluate section you might have to put it in there instead.

Anyway, should the minification be enabled for an open source android library project? I think that generally it shoudn't, because the code would be merged with the whole app's codebase and minification would then run globally.. so a better "official" fix could be to change minifyEnabled to false in this project's build.gradle. @pichillilorenzo what do you think?

cc-rock avatar Jul 23 '24 16:07 cc-rock

I still have this problem and none of solutions provided is working for me.

mustafa-fahimi avatar Jul 27 '24 10:07 mustafa-fahimi

I encountered evaluation timing issues when configure within the android/build.gradle file. To resolve this, I moved the configuration to the settings.gradle file and used the beforeProject and afterEvaluate hooks. This method worked

include ":app", ":flutter_inappwebview_android"


gradle.beforeProject { project ->
    if (project.name == "flutter_inappwebview_android") {
        project.afterEvaluate {
            if (project.hasProperty("android")) {
                project.android.buildTypes.release.minifyEnabled = false
            }
        }
    }
}

HelmiAshraf avatar Jul 28 '24 02:07 HelmiAshraf

I'm still on version 5.8.0 because of some reasons, tried both methods above from @cc-rock and @HelmiAshraf and none of them worked :(

I can see the minifyEnabled property being set to false, if I println project.android.buildTypes.release.minifyEnabledit shows minifyEnabled as false but the same R8 error keep happening :(

I also added -dontwarn android.window.** to my proguard file and it also did not work :(

Did anyone manage to build in release mode with the version 5.8? Actually, did upgrading to 6.0.0 fixes the issue or not?

edisonlsm avatar Jul 31 '24 01:07 edisonlsm

I encountered evaluation timing issues when configure within the android/build.gradle file. To resolve this, I moved the configuration to the settings.gradle file and used the beforeProject and afterEvaluate hooks. This method worked

include ":app", ":flutter_inappwebview_android"


gradle.beforeProject { project ->
    if (project.name == "flutter_inappwebview_android") {
        project.afterEvaluate {
            if (project.hasProperty("android")) {
                project.android.buildTypes.release.minifyEnabled = false
            }
        }
    }
}

After I upgrade to Gradle 8.5, this solution works.

kevinzhow avatar Aug 06 '24 05:08 kevinzhow

I'm still on version 5.8.0 because of some reasons, tried both methods above from @cc-rock and @HelmiAshraf and none of them worked :(

I can see the minifyEnabled property being set to false, if I println project.android.buildTypes.release.minifyEnabledit shows minifyEnabled as false but the same R8 error keep happening :(

I also added -dontwarn android.window.** to my proguard file and it also did not work :(

Did anyone manage to build in release mode with the version 5.8? Actually, did upgrading to 6.0.0 fixes the issue or not?

@edisonlsm I'm using 5.8.0 and I made it work with @HelmiAshraf solution but you need to change "flutter_inappwebview_android" to "flutter_inappwebview" on version "5.x.x"

alostsega avatar Aug 30 '24 04:08 alostsega

We tried @subzero911 's fix (which seems better than referencing a PR branch) but did not work for our app, because when building from clean repo, skipping the minification task caused other tasks to fail because they weren't finding the expected output (the jar file).

This is an evolution of that fix, which properly disables minification instead of skipping the task, and for us it works even when building from scratch. Add this in the android/build.gradle file:

subprojects {
    afterEvaluate {
        if (it.name == "flutter_inappwebview_android") {
            it.android.buildTypes.release.minifyEnabled = false
        }
    }
}

If your file already has a subprojects / afterEvaluate section you might have to put it in there instead.

Anyway, should the minification be enabled for an open source android library project? I think that generally it shoudn't, because the code would be merged with the whole app's codebase and minification would then run globally.. so a better "official" fix could be to change minifyEnabled to false in this project's build.gradle. @pichillilorenzo what do you think?

Since the branch is no longer available (at least I can't connect to the branch anymore when run pub get), this solution works by far.

My build.gradle is this right now:

allprojects {
    repositories {
        google()
        mavenCentral()
    }
    // --------------------- ADDED HERE ---------------------
    subprojects {
        afterEvaluate {
            if (it.name == "flutter_inappwebview_android") {
                it.android.buildTypes.release.minifyEnabled = false
            }
        }
    }
}

// AND THIS IS THE REST OF MY GRADLE...

rootProject.buildDir = '../build'
subprojects {
    project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
    project.evaluationDependsOn(':app')
}

tasks.register("clean", Delete) {
    delete rootProject.buildDir
}

Another problem, if it is a "problem", the package youtube_player_flutter: ^9.0.0 depends on flutter_inappwebview: ^6.0.0, and I cannot downgrade to inappwebview 5.8.0

Hope this package get and update soon! (8 months since last time to this days)

flechajm avatar Sep 11 '24 13:09 flechajm

Thanks bro for the update

On Wed, Sep 11, 2024, 15:42 Juan Manuel Flecha @.***> wrote:

We tried @subzero911 https://github.com/subzero911 's fix (which seems better than referencing a PR branch) but did not work for our app, because when building from clean repo, skipping the minification task caused other tasks to fail because they weren't finding the expected output (the jar file).

This is an evolution of that fix, which properly disables minification instead of skipping the task, and for us it works even when building from scratch. Add this in the android/build.gradle file:

subprojects { afterEvaluate { if (it.name == "flutter_inappwebview_android") { it.android.buildTypes.release.minifyEnabled = false } } }

If your file already has a subprojects / afterEvaluate section you might have to put it in there instead.

Anyway, should the minification be enabled for an open source android library project? I think that generally it shoudn't, because the code would be merged with the whole app's codebase and minification would then run globally.. so a better "official" fix could be to change minifyEnabled to false in this project's build.gradle. @pichillilorenzo https://github.com/pichillilorenzo what do you think?

Since the branch is no longer available (at least I can't connect to the branch anymore when run pub get), this solution works by far.

My build.gradle is this right now:

allprojects { repositories { google() mavenCentral() } // --------------------- ADDED HERE --------------------- subprojects { afterEvaluate { if (it.name == "flutter_inappwebview_android") { it.android.buildTypes.release.minifyEnabled = false } } } }

// AND THIS IS THE REST OF MY GRADLE...

rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" } subprojects { project.evaluationDependsOn(':app') }

tasks.register("clean", Delete) { delete rootProject.buildDir }

Another problem, if it is a "problem", the package youtube_player_flutter: ^9.0.0 depends on flutter_inappwebview: ^6.0.0, and I cannot downgrade to inappwebview 5.8.0

Hope this package get and update soon! (8 months since last time to this days)

— Reply to this email directly, view it on GitHub https://github.com/pichillilorenzo/flutter_inappwebview/issues/2139#issuecomment-2343712786, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMS3LJJY5VH33W4PZ3ANCNTZWBCERAVCNFSM6AAAAABHV2CYFKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNBTG4YTENZYGY . You are receiving this because you commented.Message ID: @.***>

AcuitySoftwareDev avatar Sep 11 '24 13:09 AcuitySoftwareDev

Is there any other package because it is still not working, same warning?

FlutteriPOP avatar Sep 13 '24 06:09 FlutteriPOP