juliansteenbakker / flutter_secure_storage

A Flutter plugin to store data in secure storage
https://pub.dartlang.org/packages/flutter_secure_storage
BSD 3-Clause "New" or "Revised" License
1.14k stars 391 forks source link

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

Open evgfilim1 opened 4 months ago

evgfilim1 commented 4 months ago

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

Additional notes

anisalibegic commented 4 months ago

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

evgfilim1 commented 4 months ago

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
juliansteenbakker commented 3 months ago

I will add the workaround above to the package asap.

RothaSoeurn commented 1 month ago

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

RothaSoeurn commented 1 month ago

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.

DyoungDsea commented 1 week ago

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

w568w commented 2 days ago

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.

DyoungDsea commented 2 days ago

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

MartemyanovAleksandr commented 1 day ago

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!