October 24, 2024
Chicago 12, Melborne City, USA
Android

Changing java version used by flutter


I am trying to change the java version flutter uses from 21 to 17

I have tried changing the JDK version in android studio via
Customize > All Settings > Build Tools > Gradle > Default Gradle JDK

I tried changing "SDK path" in the project file structure > Project > SDK I tried setting it to my installed java 17 aswell as using the download option in the drop down

I have tried change flutter config --jdk-dir to 1, 2 and 3. Which I get this error from doctor -v

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/tentamens/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: 2/bin/java
    ✗ Cannot execute 2/bin/java to determine the version

I have set JAVA_HOME to every result I get from whereis java including /usr/bin/java /usr/share/java /usr/lib/jvm/java-17-openjdk/
If I have JAVA_HOME set to any of the above and try and run $JAVA_HOME –version I get an output saying the version is 17

If I run java –version I get java 17

I have tried uninstalling flutter, android studio I even reinstalled my OS ( there was another issue I was facing )

I never installed java 21 it just gets installed with the setup of android studio

This is my flutter doctor -v with flutter config --jdk-dir ""

[✓] Flutter (Channel stable, 3.24.3, on Arch Linux 6.11.5-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.24.3 on channel stable at /home/tentamens/.cache/flutter_sdk
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 2663184aa7 (6 weeks ago), 2024-09-11 16:27:48 -0500
    • Engine revision 36335019a8
    • Dart version 3.5.3
    • DevTools version 2.37.3

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /home/tentamens/Android/Sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /opt/android-studio/jbr/bin/java
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✗] Chrome - develop for the web (Cannot find Chrome executable at google-chrome)
    ! Cannot find Chrome. Try setting CHROME_EXECUTABLE to a Chrome executable.

[✓] Linux toolchain - develop for Linux desktop
    • clang version 18.1.8
    • cmake version 3.30.5
    • ninja version 1.12.1
    • pkg-config version 2.1.1

[✓] Android Studio (version 2024.2)
    • Android Studio at /opt/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
    • android-studio-dir = /opt/android-studio
    • Java version OpenJDK Runtime Environment (build 21.0.3+-12282718-b509.11)

[✓] Connected device (1 available)
    • Linux (desktop) • linux • linux-x64 • Arch Linux 6.11.5-arch1-1

[✓] Network resources
    • All expected network resources are available.

I am using Arch linux with the newest flutter android studio packages all installed through pacman



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video