flutter_secure_storage
flutter_secure_storage copied to clipboard
Cannot compile my project with AGP >=8.0.0 due to R8 error
Steps to reproduce
- Create a new Flutter project.
- Add
flutter_secure_storage: ^9.2.2todependenciesofpubspec.yaml - Change AGP version to 8.5.0 in
android/settings.gradle(com.android.applicationplugin) or any other 8.x.y. - Change Gradle Wrapper version to 8.7 in
android/gradle/wrapper/gradle-wrapper.propertiesor any other which support the above specified AGP version. - Build or run Flutter app in release mode (
flutter build apkorflutter 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=falsetoandroid/gradle.propertiesdoesn't help
I'm having the same problem. There is no error when I remove flutter_secure_storage from my app.
Workaround
After applying it, the project compiles successfully and seems like no errors are emitted at runtime.
- Create a new file named
android/app/proguard-rules.proif it doesn't exist yet. - 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
I will add the workaround above to the package asap.
Execution failed for task ':app:minifyReleaseWithR8'. help me
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.
this flutter_secure_storage is the issue
Workaround
After applying it, the project compiles successfully and seems like no errors are emitted at runtime.
- Create a new file named
android/app/proguard-rules.proif it doesn't exist yet.- 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
Update: stop relying on this workaround. Just upgrade your flutter_secure_storage dependency version.
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.
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
-dontwarnlike 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 theerror_prone_annotationspackage.For
javax.annotation.Nullable, it is actually part of the optional feature called JSR 305. The most "popular" implementation available atm isspotbugs-annotations.So the solution is clear:
(Real) Workaround
Add these lines to your
android/app/build.gradle'sdependenciessection: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_storageReplace 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' }
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
-dontwarnlike 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 theerror_prone_annotationspackage.For
javax.annotation.Nullable, it is actually part of the optional feature called JSR 305. The most "popular" implementation available atm isspotbugs-annotations.So the solution is clear:
(Real) Workaround
Add these lines to your
android/app/build.gradle'sdependenciessection: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_storageReplace the version codes with the most recent ones you find in the links above.
It's realy works for me. Thank you very much!
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 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'
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/
I have merged this fix.
@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!
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