mogol / 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.12k stars 368 forks source link

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

Open evgfilim1 opened 3 months ago

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

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

evgfilim1 commented 3 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 1 month ago

I will add the workaround above to the package asap.