"error: invalid source release: 17" and other compilation issues
If you are facing a compilation error similar to this:
* What went wrong:
Execution failed for task ':package_info_plus:compileDebugJavaWithJavac'.
> error: invalid source release: 17
1. Upgrade and clean project
- Upgrade Flutter:
flutter upgrade - Upgrade project dependencies:
flutter pub upgrade - Clean project:
flutter clean - Try again.
2. Check project requirements
You can find them in the packages README.md.
For example:
- Flutter >=3.3.0
- Dart >=2.18.0 <4.0.0
- Android compileSDK 34
- Java 17
- Android Gradle Plugin >=8.3.0
- Gradle wrapper >=8.4
Check that your project is using Java 17.
Run flutter doctor -v and find the Android section, for example:
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /home/xyz/Android/Sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /home/xyz/Android/Sdk
• Java binary at: /snap/android-studio/155/jbr/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
• All Android licenses accepted.
3. Upgrade Android Studio
To ensure that you are using the right OpenJDK Java version, install the latest version of Android Studio, and perform a flutter clean.
4. If nothing else works:
[!NOTE] If compilation errors persist after following this guide, please search on Stack Overflow or Google before creating a new issue ticket.
- Check on StackOverflow: https://stackoverflow.com/search?q=error+invalid+source+release+17
- Check on Google: https://www.google.com/search?q=error+invalid+source+release+17
- Check on this issue tracker: https://github.com/fluttercommunity/plus_plugins/issues?q=error+invalid+source+release+17
If all the above fails, then create a compilation error ticket using this template: Compile Error Template
I will leave this ticket open and pinned for visibility. Any opened issues regarding this can me marked as duplicated and linked to this.
Since we haven't got any issues related to this for a while, closing the ticket and unpinning.