21

I'm editing java files in a package of my flutter project, but it is build with source 1.7, how can I change it?

enter image description here

[√] Flutter (Channel dev, 1.27.0-8.0.pre, on Microsoft Windows [Version 10.0.18363.1440], locale ru-RU)
• Flutter version 1.27.0-8.0.pre at C:\Users\USER\flutter
• Framework revision b7d4806243 (5 weeks ago), 2021-02-19 09:22:45 -0800
• Engine revision 6993cb229b
• Dart version 2.13.0 (build 2.13.0-30.0.dev)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at C:\Users\USER\AppData\Local\Android\sdk
• Platform android-30, build-tools 30.0.3
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.

[√] Android Studio (version 4.1.0)
• Android Studio at C:\Program Files\Android\Android Studio
• 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 1.8.0_242-release-1644-b01)

enter image description here enter image description here

9
  • 1
    make sure your JAVA_HOME point to the target JDK ? Commented Mar 29, 2021 at 11:55
  • @elgarnaoui yes Commented Mar 29, 2021 at 13:10
  • 2
    Go to File > Project Structure. Select the SDK Location section in the list of the left. Deselect the Use embedded JDK (recommended) option. Enter the absolute path of your installed JDK in the text box. Commented Mar 29, 2021 at 13:14
  • Finally, Verify your Flutter points to JDK, here it is pointing to JRE not JDK, once you make changes as suggested by elgarnoui Commented Mar 29, 2021 at 13:20
  • @elgarnaoui, you can see my Project Structure window on the second image from the bottom. Looks like 'Use embedded JDK' has been removed in 4.x, so correct path to jdk is set in '15', which is also selected in all 'Android API Platform'. Commented Mar 29, 2021 at 14:24

2 Answers 2

29

Run the following command:

flutter config --jdk-dir <path_to_jdk>

If you rerun flutter doctor --verbose after this you should see it now updated.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much, man. You made my day. This should be the accepted answer. Clicking in the UI of Android Studio didn't help at all.
I think that can help before check the JAVA_HOME path, with echo $JAVA_HOME
3

Make the switch to JDK 11 by following the steps in this post. Once done, restart Android Studio and try clearing its cache.

1 Comment

If someone is using VS code and emulator from there to run flutter, it's likely that this answer won't solve the problem. We need to tell the flutter environment to use the specific JDK. If we run flutter doctor --verbose under the android toolchain section, we can find the JDK version that's being used and its location. Then if we want, we can change it using flutter config --jdk-dir <path_to_jdk>. You can find also find the local JAVA_HOME path using echo $JAVA_HOME and use that as '<path_to_jdk>'. (credit to @samir for the main answer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.