Flutter unable to locate Java Runtime after updating Android Studio? - java

I updated android studio to Electric El, but after updating, it is unable to find Java Runtime.
Flutter doctor gives this error and the code does not compile.
maazaftab#maazs-MacBook-Pro edge-focus-mobile % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
[✓] Flutter (Channel beta, 3.7.0-1.2.pre, on macOS 13.0.1 22A400 darwin-arm64, locale en-PK)
[!] Android toolchain - develop for Android devices (Android SDK version 31.0.0)
✗ Could not determine java version
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2022.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
! Doctor found issues in 2 categories.

In your zshrc file add.
export JAVA_HOME=/Applications/Android\ Studio.app/Contents/jbr/Contents/Home
Restart the android studio. Flutter doctor will give this.
maazaftab#maazs-MacBook-Pro edge-focus-mobile % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 3.7.0-1.2.pre, on macOS 13.0.1 22A400 darwin-arm64, locale en-PK)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.1)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] IntelliJ IDEA Community Edition (version 2022.3)
[✓] VS Code (version 1.62.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
You can ignore the warning ✗ Unable to find bundled Java version. but the code will compile successfully.

Open the folder where Android Studio is installed.
In most cases, it is "C:\Program Files\Android\Android Studio"
Open the "jbr" folder inside the Android Studio folder ("C:\Program Files\Android\Android Studio\jbr"), and copy all contents in it.
Then go back and create a new folder called "jre" -> "C:\Program Files\Android\Android Studio\jre"
Paste all contents which you copied from "jbr" folder to "jre" folder.
Click Start and search for "Environment" and open "Edit the Environment variables" from search result.
Click to open "Environment variables"
On "User variables" pane click new and add new variable with name "JAVA_HOME" and path "C:\Program Files\Android\Android Studio\jre". Click OK to save.
Restart Android Studio and run flutter doctor. It will solve the problem.
Android Studio folder screenshot
Environment screenshot

Related

Unable to find bundled java version. flutter doctor

I'm facing this issue on windows after upgrading Android Studio to Electric Eel.
flutter doctor returns:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 3.3.10, on Microsoft Windows [Version 10.0.22621.1105], locale en-US)
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[√] Chrome - develop for the web
[!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.3)
X The current Visual Studio installation is incomplete. Please reinstall Visual Studio.
[!] Android Studio (version 2022.1)
X Unable to find bundled Java version.
[√] VS Code (version 1.74.3)
[√] Connected device (4 available)
[√] HTTP Host Availability
! Doctor found issues in 2 categories.
I've tried adding a JAVA_HOME kind of solution but didn't work for me.
I had that problem today after updating Android Studio, and found an answer here:
https://github.com/flutter/flutter/issues/118502
The solution is basically:
Go to your AndroidStudio folder (normally C:\Program Files\Android\Android Studio in Windows)
Copy the content of jbr and paste the content into jre folder
Quick workaround from here: https://github.com/flutter/flutter/issues/118502#issuecomment-1384954269
Run in the terminal:
cd /Applications/Android\ Studio.app/Contents
ln -s jbr jre
*solution for MacOS

Failing to launch my Flutter application on my android device [duplicate]

I installed Android Studio 4.1 and tried to run the existing project. But it gives an error like this:
ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation.
You have to set the JAVA_HOME Environment Variable.
On Windows, I solved the issue as follows:
Download the Java JDK from here and install it. (This links to version 15, which requires you to create an account in order to download. Version 16 is available to download without creating an account, but it has caused me an error that required me to downgrade.)
Set the "JAVA_HOME" Environment Variable:
Open Windows Search, type in “env”, and choose “Edit the system environment variables”.
Click on "Environment Variables...".
Click on "New".
Fill in the "variable name" field with "JAVA_HOME".
Fill in the "variable value" with the path to where Java is installed on your computer. (for me it was under "C:\Program Files\Java\<jdkversion>".)
Click "OK" and close all dialogs.
Restart your IDE / Terminal. (do not skip this step)
On Ubuntu 20.04 with Android 4.1, this error can be solved using the Snap version with:
flutter config --android-studio-dir=/snap/android-studio/current/android-studio
For Windows :
flutter config --android-studio-dir="C:\Program Files\Android\Android Studio"
This command works fine if you have Android Studio installed. Flutter can understand the configurations of the Android Studio and you don't have to provide JAVA_HOME anymore.
Edit (Bonus) :
Also, download "Android SDK Command-line Tools" in android studio for android-licenses. Steps are shown in the image below.
You need to install Java JDK software which is required for the android studio.
sudo apt install openjdk-11-jdk
UPDATE: run flutter upgrade to upgrade to Flutter 1.22.2, which fixes compatibility issues with Android Studio 4.1. See related Flutter release.
This issue has been resolved v
See this issue regarding Android Studio 4.1 and Flutter
You can either downgrade back to Android Studio 4.0.2 or you can
install the latest JDK and update your JAVA_HOME variable and
PATH (OS dependent).
Note that if you choose to continue using 4.1 instead of downgrading,
flutter doctor will tell you Android Studio is not installed.
You need to run flutter config --android-studio-dir='<path to android studio>' in order to fix this issue. flutter doctor will now also
incorrectly report that the Flutter and Dart plugins are not
installed even if they are - you can ignore this.
Install Android Studio (skip this step if you already installed)
Goto
C:\Program Files\Android\Android Studio\jre and copy the path.
Make New variable called "JAVA_HOME". And paste above path as the variable value.
I set my JAVA HOME to the path,
/snap/android-studio/97/android-studio/jre/
Then I set my android studio config in flutter by using this command:
flutter config --android-studio-dir=/snap/android-studio/current/android-studio
My system is :
Ubuntu 20.04 with Flutter plugin version as 4.1,
In Mac:
In your terminal run
ECHO $JAVA_HOME
This will bring up the current path of java home.Pay close attention to the path that the terminal outputs.In my case i had System/Library instead of /Library/.../... typo as my path.So i simply corrected this in bash_profile.
If your path is correct but the error persists,
Right Click On Finder
Go To Folder
Bash_Profile
Add or Edit the Java Home Path
The path you add here should be the one your terminal output when you ran Echo $Java_Home..As long as this path that was echoed was/is correct..the below steps should fix the issue.
Then open your zshrc in a similar manner as you did with bash_profile and add the home path to the file.
You can also edit the bash_profile and zshrc files in your text editor.These files can be displayed using cmd + shift + . in your home folder.
After that,save,exit the terminal, close android studio and restart your machine.
Read this Article to learn more.
Locate where your Android Studio is installed.
For me C:\Program Files\Android\Android Studio
Check if the jre folder exists, Create a new folder called jre
Copy the contents of the jbr folder and paste them into the jre folder.
Check by running flutter doctor, and Restart IDE.
Thanks: roufy235 {cause}
For ubuntu 20.04 this solution will be appropriate: -
This link solved my problem. In short I would recommend to follow the simple steps, i.e.
Upgrade the flutter using flutter upgrade
Set the path of the flutter flutter config --android-studio-dir="/path/to/android/studio/"
Set the path in bashrc file by opening bashrc file(it is a hidden file)
export JAVA_HOME="/path/to/android/studio/jre/"
choco install javaruntime
If you use choco package manager. It will set the vars automatically.
This issue can also be caused if you have updated your Android Studio.
In that case.
For Windows
First Open the Users\username\AppData\Local\Google directory on your PC/Laptop and make sure to Delete the older version of your Android Studio.
e.g, Current version of Android studio is Electric Eel (2022.1).
Delete any other older version from that directory accordingly and restart your PC or Laptop.
Then try running your project.
Install openjdk-8 ....
You have to restart your terminal, the issue will persist even after download if you don't restart the terminal.
Follow react native guide to download openjdk for your environment. ...
https://reactnative.dev/docs/environment-setup
For Windows this worked
Go to C:\Program Files\Android\Android Studio.
Copy all the files inside of jbr directory.
Paste all the files into jre directory.
Then run flutter doctor. The issue will go away.
D:\Flutterproject\rechyriedapp>flutter doctor -v
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.22621.1105], locale en-IN)
• Flutter version 3.3.8 on channel stable at C:\flutter_windows_3.3.8\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 52b3dc25f6 (3 months ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0
[!] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\USER\AppData\Local\Android\Sdk
• Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
X No Java Development Kit (JDK) found; You must have the environment variable JAVA_HOME set and the java binary in your PATH. You can download the JDK from https://www.oracle.com/technetwork/java/javase/downloads/.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.4.33213.308
• Windows 10 SDK version 10.0.22000.0
[!] Android Studio (version 2022.1)
• 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
X Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
[√] Connected device (4 available)
• CPH2095 (mobile) • 86db9605 • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1105]
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.120
• Edge (web) • edge • web-javascript • Microsoft Edge 109.0.1518.55
[√] HTTP Host Availability
• All required HTTP hosts are available
! Doctor found issues in 2 categories.
After that copy all file from jbr to jre
D:\Flutterproject\rechyriedapp>flutter doctor -v
[√] Flutter (Channel stable, 3.3.8, on Microsoft Windows [Version 10.0.22621.1105], locale en-IN)
• Flutter version 3.3.8 on channel stable at C:\flutter_windows_3.3.8\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 52b3dc25f6 (3 months ago), 2022-11-09 12:09:26 +0800
• Engine revision 857bd6b74c
• Dart version 2.18.4
• DevTools version 2.15.0
Checking Android licenses is taking an unexpectedly long time...[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\USER\AppData\Local\Android\Sdk
• Platform android-TiramisuPrivacySandbox, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.4.4)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.4.33213.308
• Windows 10 SDK version 10.0.22000.0
[√] Android Studio (version 2022.1)
• 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 11.0.15+0-b2043.56-8887301)
[√] Connected device (4 available)
• CPH2095 (mobile) • 86db9605 • android-arm64 • Android 12 (API 31)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.22621.1105]
• Chrome (web) • chrome • web-javascript • Google Chrome 109.0.5414.120
• Edge (web) • edge • web-javascript • Microsoft Edge 109.0.1518.55
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
Download Liberica JDK and on installation it will automatically set JAVA_HOME environment variable.
Now you just go to Android Studio -> Project Structure -> SDK -> Point all jdk path to liberica jdk installation directory and apply.
You are done. Just restart android studio and gradle command will work.

Flutter codes not executing on android emulator

C:\Users\TomiwaPC>flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Version 10.0.18362.30], locale en-NG)
[√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc2)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] Connected device (2 available)
• No issues found!
I have upgraded my flutter. Done everything I could
No error was reported.
Please I would like to know how i can resolve this issue.
Please find below the links to screenshots for some clarification:
[flutter and emulator screenshots][1]
[1]: https://i.stack.imgur.com/Sz0Aq.png
[android sdk screenshots][2]
[2]: https://i.stack.imgur.com/jS3og.png
[project structure screenshots][3]
[3]: https://i.stack.imgur.com/PU25L.png
I would be glad if you can assist with your experience.
Thanks in anticipation
Have you made sure that in the emulator is connected? I use android studio and there is a dropdown menu to select an emulator.
Here's what my one looks like, it's at the top toolbar section:
Run flutter devices and ensure your device is listed, then run flutter run in your project directory.
Did you run "flutter pub get" on the terminal for fetching dependencies before running the project?

Try re-installing or updating your Android SDK Manager

I am trying to install Flutter Enviroment and I found this error when I use this command:
[√] Flutter (Channel stable, v1.12.13+hotfix.8, on Microsoft Windows [Version 10.0.18362.720], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit https://flutter.dev/setup/#android-setup for detailed
instructions.
[√] Android Studio (version 3.6)
[√] VS Code (version 1.43.1)
[!] Connected device
! No devices available
So When I use flutter doctor --android-licenses I found this error also:
A newer version of the Android SDK is required. To update, run:
C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update
When I tried to run this command C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update I found this error:
Error: Could not find or load main class '-XX:+IgnoreUnrecognizedVMOptions
Caused by: java.lang.ClassNotFoundException: '-XX:+IgnoreUnrecognizedVMOptions
So any one knows hoe to solve this problem
Go to the directory C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\
and then write the command:
sdkmanager --update
After that, run:
flutter doctor --android-licenses
You don't need to reinstall flutter.
You should just go to android studio->sdk manager-> sdk tools-> clear tick from Hide Obsolete Packages and tick Android Sdk tools (Obsolete) in order to install.
Finally it will be installed and you will able use flutter.
P.s. Don't forget to run to flutter doctor)
The Screenshot
Navigate in cmd to the needed folder. I think it was:
cd C:\Users\DELL\AppData\Local\Android\Sdk\tools\bin\sdkmanager --update
After this run the flutter doctor command.

Android license status unknown and a weird problem

Steps to Reproduce
I am running flutter in windows 10. I previously had a running android setup. After cloning the flutter repo and updating path, I ran flutter doctor -v. The logs are below. Now after searching a bit for solving the problem, I came across to this solution from various stackoverflow answers: Flutter.io Android License Status Unknown
I at first executed this:
set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
Though I don't know how to make it permanent. Then after running flutter doctor again, I came with another message, see log ###2
So it says Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4). So I ran flutter doctor --android-licenses accordingly. And it gives another error, that is:
A newer version of the Android SDK is required. To update, run:
C:\Users\imazi\AppData\Local\Android\sdk\tools\bin\sdkmanager --update
Well, so I ran C:\Users\imazi\AppData\Local\Android\sdk\tools\bin\sdkmanager --update to update it. And it kinda updated successfully outputting [=======================================] 100% Computing updates...
So I thought the issue is solved and ran flutter doctor again but it seems that nothing has been changed the problem still remains. It is like a loop. I do everything and the problem remains as it is. The output of the last flutter doctor is in log ### 3
My java version is:
10.0.2 2018-07-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.2+13)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.2+13, mixed mode)
Please help.
!! also opened a github issue here: https://github.com/flutter/flutter/issues/39637
Logs
1 flutter doctor -v
O:\Flutter installation>flutter doctor -v
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
• Flutter version 1.7.8+hotfix.4 at O:\Work_Anon\Flutter installation\flutter
• Framework revision 20e59316b8 (6 weeks ago), 2019-07-18 20:04:33 -0700
• Engine revision fee001c93f
• Dart version 2.4.0
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
**• Android SDK at C:\Users\imazi\AppData\Local\Android\sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-29, build-tools 29.0.1
• Java binary at: O:\Work_Anon\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
**X Android license status unknown.
Try re-installing or updating your Android SDK Manager.
See https://developer.android.com/studio/#downloads or visit
https://flutter.dev/setup/#android-setup for detailed instructions.****
[!] Android Studio (version 3.4)
• Android Studio at O:\Work_Anon\Android Studio
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1343-b01)
[!] Connected device
! No devices available
2 flutter doctor after set JAVA_OPTS=-XX:+IgnoreUnrecognizedVMOptions --add-modules java.se.ee
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
3 last flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.7.8+hotfix.4, on Active code page: 1252
Microsoft Windows [Version 10.0.18362.295], locale en-US)
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1))
! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses
[!] Android Studio (version 3.4)
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
[!] Connected device
! No devices available
Actually, the problem got solved after installing jdk 8 and setting JAVA_HOME accordingly this new jdk. Also in the sdkmanager.bat file, located in C:\Users\username\AppData\Local\Android\Sdk\tools\bin
I added the line set JAVA_HOME="C:\Program Files\Java\jdk1.8.0_221"
No need to uninstall java 10. That solved the whole problem!
Check if the flutter path is added.
Restart your system
Then run flutter doctor --android-licenses
accept all the licenses that appear
again run flutter doctor
and check if the issue persists
I uninstall the java jdk from my system and then let my flutter doctor arise that error of " [!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)"
and then followed the solution that flutter doctor was giving as it says to run the command " flutter doctor --android-licenses " and then type " y " as it says you to accept the licenses provided to solve this problem of "[!] Android toolchain - develop for Android devices (Android SDK version 29.0.1)" and then I again ran flutter doctor and the problem was resolved.

Categories

Resources