flutter_secure_storage: v5.0.0: error: lambda expressions and method references are not supported in -source 7 (use -source 8 or higher to enable)
I encountered a compiler error when trying to build with flutter_secure_storage v5.0.0
.
I was able to fix by adding compileOptions
to specify Java v8 compatibility to your build.gradle
:
Version:
flutter_secure_storage: ^5.0.0
Compile error:
/Users/user/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-5.0.0/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStoragePlugin.java:250: error: lambda expressions are not supported in -source 7
handler.post(() -> methodResult.success(result));
^
(use -source 8 or higher to enable lambda expressions)
/Users/user/.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-5.0.0/android/src/main/java/com/it_nomads/fluttersecurestorage/FlutterSecureStoragePlugin.java:260: error: method references are not supported in -source 7
handler.post(methodResult::notImplemented);
^
(use -source 8 or higher to enable method references)
2 errors
FAILURE: Build failed with an exception.
Fix:
I was able to get past the compiler errors by specifying the following compileOptions
in the android
block in:
.../.pub-cache/hosted/pub.dartlang.org/flutter_secure_storage-5.0.0/android/build.gradle
android {
compileSdkVersion 31
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
defaultConfig {
minSdkVersion 18
targetSdkVersion 31
versionCode 6
versionName "3.3.1"
}
lintOptions {
disable 'InvalidPackage'
}
}
flutter doctor -v
[✓] Flutter (Channel stable, 2.5.3, on macOS 12.0.1 21A559 darwin-x64, locale en-US)
• Flutter version 2.5.3 at /Users/user/Documents/Projects/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 18116933e7 (4 weeks ago), 2021-10-15 10:46:35 -0700
• Engine revision d3ea636dc5
• Dart version 2.14.4
[✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
• Android SDK at /Users/user/Library/Android/sdk
• Platform android-31, build-tools 31.0.0
• Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 13.0, Build version 13A233
• CocoaPods version 1.11.2
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2020.3)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[✓] VS Code (version 1.62.2)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.28.0
[✓] Connected device (2 available)
• Nexus 5X (mobile) • 0256574f4c681f87 • android-arm64 • Android 8.1.0 (API 27)
• Chrome (web) • chrome • web-javascript • Google Chrome 95.0.4638.69
• No issues found!
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 20
The fix is to add the following to your own app project:
I have tried the following:
So i have added the compile options and publish version 5.0.2
I have tried the same as above with version 5.0.2 and i didn’t get any warning anymore. So please try version 5.0.2 and report if it works or not.
EDIT: Please use version 5.0.2 as it also fixes another issue #332
@nezoat’s this does not work for us
In file
android/gradle/wrapper/gradle-wrapper.properties
changingto
and then running
we still see the original error
Thanks for reporting, i have added your suggested fix and will release it asap.
@juliansteenbakker Thanks much … yes, confirming that the latest version 5.0.2 builds fine for me now. Closing issue.
@juliansteenbakker 5.0.2 works for me. Thank you for the quick reaction! 😃
@Cupidon277 confirmed this is working. Also, JDK11 or above must be installed to upgrade to Gradle 7
Hello guys, I had the same issue and following this thread I fixed it doing the following:
Disclaimer: I started learning Flutter literally two days ago, don’t judge if I misused any of the steps below.
Long story short for the experts here, upgrade Gradle to 7+
Below is what I did to solve it
First I ran the
./gradlew --version
command in the android directory of my project and got the following information:Gradle 6.4 Kotlin: 1.5.31 Groovey: 3.0.9 JVM: 11.0.11
Then as juliansteenbakker mentioned I followed the provided link
https://developer.android.com/studio/releases/gradle-plugin#updating-plugin
And: 1- Installed gradle 7 by changing the gradle version to
gradle-7.3-all.zip
in the fileandroid/gradle/wrapper/graddle-wrapper.properties
2- (I am not sure this helps but I have done it anyways?) From terminal project root, ran the commandflutter upgrade-packages
thenflutter clean
thenflutter pub get
3 - Changed the Gradle version in dependencies in theandroid/build.gradle
file as mentioned in the previous link like this:class path 'com.android.tools.build:gradle:7.0.0'
4- From terminal changed directory to android and ran the command./gradlew clean
Then i ran again the command
./gradlew --version
from theandroid
directory and got the output:Gradle 7.3 . . .
I am facing the same problem but none of the suggestion would fix it.
Thanks for the clarification. I’ll be waiting for the release @juliansteenbakker
I’m facing the same problem. I couldn’t fix it using
compileOptions
.