flutter_secure_storage icon indicating copy to clipboard operation
flutter_secure_storage copied to clipboard

Cannot compile my project with AGP >=8.0.0 due to R8 error

Open evgfilim1 opened this issue 1 year ago • 5 comments
trafficstars

Steps to reproduce

  1. Create a new Flutter project.
  2. Add flutter_secure_storage: ^9.2.2 to dependencies of pubspec.yaml
  3. Change AGP version to 8.5.0 in android/settings.gradle (com.android.application plugin) or any other 8.x.y.
  4. Change Gradle Wrapper version to 8.7 in android/gradle/wrapper/gradle-wrapper.properties or any other which support the above specified AGP version.
  5. Build or run Flutter app in release mode (flutter build apk or flutter run --release).

Expected behavior

Builds successfully

Actual behavior

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /home/evgfilim1/Projects/flutter_experiments/build/app/outputs/mapping/devRelease/missing_rules.txt.
ERROR: R8: Missing class com.google.errorprone.annotations.CanIgnoreReturnValue (referenced from: com.google.crypto.tink.KeysetManager com.google.crypto.tink.KeysetManager.add(com.google.crypto.tink.KeyTemplate) and 52 other contexts)
Missing class com.google.errorprone.annotations.CheckReturnValue (referenced from: com.google.crypto.tink.InsecureSecretKeyAccess and 1 other context)
Missing class com.google.errorprone.annotations.Immutable (referenced from: com.google.crypto.tink.InsecureSecretKeyAccess and 40 other contexts)
Missing class com.google.errorprone.annotations.RestrictedApi (referenced from: com.google.crypto.tink.aead.AesEaxKey$Builder com.google.crypto.tink.aead.AesEaxKey.builder() and 6 other contexts)
Missing class javax.annotation.Nullable (referenced from: java.lang.Object com.google.crypto.tink.PrimitiveSet$Entry.fullPrimitive and 86 other contexts)
Missing class javax.annotation.concurrent.GuardedBy (referenced from: com.google.crypto.tink.proto.Keyset$Builder com.google.crypto.tink.KeysetManager.keysetBuilder and 3 other contexts)

FAILURE: Build failed with an exception.

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

* 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 35s

Versions

  • Flutter (Channel beta, 3.23.0-0.1.pre, on Arch Linux 6.9.7-zen1-1-zen, locale en_US.UTF-8)
  • Android SDK version 35.0.0
  • flutter_secure_storage: ^9.2.2

Additional notes

  • The issue is not reproducible on AGP <8.0.0
  • Adding android.enableR8.fullMode=false to android/gradle.properties doesn't help

evgfilim1 avatar Jul 04 '24 08:07 evgfilim1

I'm having the same problem. There is no error when I remove flutter_secure_storage from my app.

anisalibegic avatar Jul 04 '24 13:07 anisalibegic

Workaround

After applying it, the project compiles successfully and seems like no errors are emitted at runtime.

  1. Create a new file named android/app/proguard-rules.pro if it doesn't exist yet.
  2. Copy-paste the content below to the file.
# https://github.com/mogol/flutter_secure_storage/issues/748
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn com.google.errorprone.annotations.RestrictedApi
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.concurrent.GuardedBy

evgfilim1 avatar Jul 04 '24 15:07 evgfilim1

I will add the workaround above to the package asap.

juliansteenbakker avatar Aug 13 '24 21:08 juliansteenbakker

Execution failed for task ':app:minifyReleaseWithR8'. help me

RothaSoeurn avatar Oct 08 '24 03:10 RothaSoeurn

ERROR: Missing classes detected while running R8. Please add the missing classes or apply additional keep rules that are generated in /Users/macbook/projects/tenh100-ecom/build/app/outputs/mapping/release/missing_rules.txt. ERROR: R8: Missing class org.slf4j.impl.StaticLoggerBinder (referenced from: void org.slf4j.LoggerFactory.bind() 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

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

RothaSoeurn avatar Oct 08 '24 03:10 RothaSoeurn

this flutter_secure_storage is the issue

Workaround

After applying it, the project compiles successfully and seems like no errors are emitted at runtime.

  1. Create a new file named android/app/proguard-rules.pro if it doesn't exist yet.
  2. Copy-paste the content below to the file.
# https://github.com/mogol/flutter_secure_storage/issues/748
-dontwarn com.google.errorprone.annotations.CanIgnoreReturnValue
-dontwarn com.google.errorprone.annotations.CheckReturnValue
-dontwarn com.google.errorprone.annotations.Immutable
-dontwarn com.google.errorprone.annotations.RestrictedApi
-dontwarn javax.annotation.Nullable
-dontwarn javax.annotation.concurrent.GuardedBy

this solved the problem

DyoungDsea avatar Nov 18 '24 10:11 DyoungDsea

Update: stop relying on this workaround. Just upgrade your flutter_secure_storage dependency version.


For anyone caring about this issue: **it is a really, really bad workaround to suppress all errors with `-dontwarn`. It could theoretically break your project or crash your app.**

This error, which was a compile warning before AGP 8.0, has now been elevated to a compile error. Essentially, it is trying to tell you that some classes referenced in your project cannot be found.

In some cases, you can still ignore it completely using -dontwarn like you did before AGP 8.0; however, in most cases, you should find the missing classes rather than suppressing the error to avoid ignoring the underlying issues.

Let's take a look at the missing classes in this issue:

For com.google.errorprone.annotations.*, it's clear that it is part of the error_prone_annotations package.

For javax.annotation.Nullable, it is actually part of the optional feature called JSR 305. The most "popular" implementation available atm is spotbugs-annotations.

So the solution is clear:

(Real) Workaround

Add these lines to your android/app/build.gradle's dependencies section:

implementation 'com.google.errorprone:error_prone_annotations:2.36.0' // required by flutter_secure_storage
implementation 'com.github.spotbugs:spotbugs-annotations:4.8.6' // required by flutter_secure_storage

Replace the version codes with the most recent ones you find in the links above.

And don't forget to remove the incorrect -dontwarn lines from your proguard-rules.pro.

w568w avatar Nov 28 '24 11:11 w568w

For anyone caring about this issue: it is a really, really bad workaround to suppress all errors with -dontwarn.

This error, which was a compile warning before AGP 8.0, has now been elevated to a compile error. Essentially, it is trying to tell you that some classes referenced in your project cannot be found.

In some cases, you can still ignore it completely using -dontwarn like you did before AGP 8.0; however, in most cases, you should find the missing classes rather than suppressing the error to avoid ignoring the underlying issues.

Let's take a look at the missing classes in this issue:

For com.google.errorprone.annotations.*, it's clear that it is part of the error_prone_annotations package.

For javax.annotation.Nullable, it is actually part of the optional feature called JSR 305. The most "popular" implementation available atm is spotbugs-annotations.

So the solution is clear:

(Real) Workaround

Add these lines to your android/app/build.gradle's dependencies section:

implementation 'com.google.errorprone:error_prone_annotations:2.36.0' // required by flutter_secure_storage
implementation 'com.github.spotbugs:spotbugs-annotations:4.8.6' // required by flutter_secure_storage

Replace the version codes with the most recent ones you find in the links above.

dependencies { implementation 'com.google.errorprone:error_prone_annotations:2.36.0' implementation 'com.github.spotbugs:spotbugs-annotations:4.8.6' }

DyoungDsea avatar Nov 28 '24 13:11 DyoungDsea

For anyone caring about this issue: it is a really, really bad workaround to suppress all errors with -dontwarn.

This error, which was a compile warning before AGP 8.0, has now been elevated to a compile error. Essentially, it is trying to tell you that some classes referenced in your project cannot be found.

In some cases, you can still ignore it completely using -dontwarn like you did before AGP 8.0; however, in most cases, you should find the missing classes rather than suppressing the error to avoid ignoring the underlying issues.

Let's take a look at the missing classes in this issue:

For com.google.errorprone.annotations.*, it's clear that it is part of the error_prone_annotations package.

For javax.annotation.Nullable, it is actually part of the optional feature called JSR 305. The most "popular" implementation available atm is spotbugs-annotations.

So the solution is clear:

(Real) Workaround

Add these lines to your android/app/build.gradle's dependencies section:

implementation 'com.google.errorprone:error_prone_annotations:2.36.0' // required by flutter_secure_storage
implementation 'com.github.spotbugs:spotbugs-annotations:4.8.6' // required by flutter_secure_storage

Replace the version codes with the most recent ones you find in the links above.

It's realy works for me. Thank you very much!

MartemyanovAleksandr avatar Nov 29 '24 18:11 MartemyanovAleksandr

This problem is probably fixed with version v10.0.0-beta.1. If you still encounter it with this version, please let me know.

juliansteenbakker avatar Jan 06 '25 15:01 juliansteenbakker

@juliansteenbakker I still have the issue with flutter_secure_storage v10.0.0-beta.2 and Flutter v3.24.3.

Adding the following to android/app/build.gradle's dependencies fixes it:

// This is a temporary fix for https://github.com/mogol/flutter_secure_storage/issues/748
implementation 'org.slf4j:slf4j-api:2.0.16'

AhmedLSayed9 avatar Jan 07 '25 20:01 AhmedLSayed9

Could you please check if this version compiles correctly in release mode:

  flutter_secure_storage:
    git:
      url: https://github.com/juliansteenbakker/flutter_secure_storage
      ref: fix/release-build
      path: flutter_secure_storage/

juliansteenbakker avatar Jan 08 '25 12:01 juliansteenbakker

I have merged this fix.

juliansteenbakker avatar Jan 09 '25 14:01 juliansteenbakker

@juliansteenbakker I've tested it again using flutter_secure_storage v10.0.0-beta.2 and somehow it's working now. I can't find the reason though. Maybe, because I've downgraded the Java version used by Flutter (Downgraded from v21 to v19). Thanks anyway!

AhmedLSayed9 avatar Jan 09 '25 17:01 AhmedLSayed9

A fix for this is available on version flutter_secure_storage 9.2.4

You can also read the changelog doc to confirm here -> https://pub.dev/packages/flutter_secure_storage/changelog

unknownaloy avatar Jan 23 '25 07:01 unknownaloy