Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error with latest flutter/agp versions #2139

Closed
2 tasks done
holzgeist opened this issue May 14, 2024 · 37 comments
Closed
2 tasks done

Build error with latest flutter/agp versions #2139

holzgeist opened this issue May 14, 2024 · 37 comments
Labels
bug Something isn't working

Comments

@holzgeist
Copy link

holzgeist commented May 14, 2024

  • I have read the Getting Started section
  • 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 holzgeist added the bug Something isn't working label May 14, 2024
Copy link

👋 @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!

@komaxx
Copy link

komaxx commented May 15, 2024

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.

@Augustinekan
Copy link

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

@komaxx
Copy link

komaxx commented May 15, 2024

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

@holzgeist
Copy link
Author

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

@flechajm
Copy link

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!

@specOper99
Copy link

specOper99 commented May 19, 2024

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

@Yohan-J
Copy link

Yohan-J commented May 20, 2024

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 *;
}

@nayanbabariya
Copy link

@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.

@Yohan-J
Copy link

Yohan-J commented May 20, 2024

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

@nayanbabariya
Copy link

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

@specOper99
Copy link

@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.

@max-anders
Copy link

max-anders commented Jun 13, 2024

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

@davemg3
Copy link

davemg3 commented Jun 15, 2024

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

@toshiossada
Copy link

the same here

@ttb-inc
Copy link

ttb-inc commented Jun 20, 2024

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.

@AcuitySoftwareDev
Copy link

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?

@komaxx
Copy link

komaxx commented Jul 1, 2024

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.

@AcuitySoftwareDev
Copy link

AcuitySoftwareDev commented Jul 5, 2024 via email

@subzero911
Copy link

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.

@kevinzhow
Copy link

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

@cc-rock
Copy link

cc-rock commented Jul 23, 2024

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?

@mustafa-fahimi
Copy link

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

@HelmiAshraf
Copy link

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
            }
        }
    }
}

@edisonlsm
Copy link

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?

@kevinzhow
Copy link

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.

emirhalici added a commit to GemstoneLights/flutter_inappwebview that referenced this issue Aug 22, 2024
Fixes build error, related to pichillilorenzo#2139
@alostsega
Copy link

alostsega commented Aug 30, 2024

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"

@flechajm
Copy link

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)

@AcuitySoftwareDev
Copy link

AcuitySoftwareDev commented Sep 11, 2024 via email

@FlutteriPOP
Copy link

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

@phamconganh
Copy link

phamconganh commented Sep 13, 2024

For everyone who wants hotfix and waiting for update. You can comment version com.android.application 8+ in android/settings.gradle

plugins {
    // id "com.android.application" version "8.1.0" apply false
    id "com.android.application" version "7.3.0" apply false
}

@FlutteriPOP
Copy link

For everyone who wants hotfix and waiting for update. You can comment version com.android.application 8+ in android/settings.gradle

plugins {
    // id "com.android.application" version "8.1.0" apply false
    id "com.android.application" version "7.3.0" apply false
}

Thanks, now its working perfectly

@thobiassilva
Copy link

Any update?

@tungpham6195
Copy link

Fixed in v6.1.1
Screenshot 2024-10-02 at 22 42 45

@pichillilorenzo
Copy link
Owner

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 I think you are right, so the developer should know what to "-keep" inside the proguard-rules.pro file of the his/her App in case the minification is enabled.
Doing so now could be a breaking change, so it could be part of the next major version.

@MuddassarElexoft
Copy link

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

This works with release builds, But I am unable to open browser any idea why.

Copy link

github-actions bot commented Nov 5, 2024

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests