Hitting a bit of a wall here when trying to build a brand new flutter sandbox application within IntelliJ for Android.
The error that I get is the following:
java: Cannot run program "/Users/vintrin/Library/AndroidStudio/sdk/bin/java" (in directory "/Users/vintrin/Library/Caches/JetBrains/IntelliJIdea2022.3/compile-server"): error=2, No such file or directory
This file /Users/vintrin/Library/AndroidStudio/sdk/bin/java in fact does NOT exist.
I am starting the IntelliJ from my terminal to get all the environment variables to be recognized by IntelliJ using
open -na "IntelliJ IDEA.app"
Below you can see the print out of the values from within the IntelliJ terminal:
Viktors-MacBook-Pro:flutter_sandbox vintrino$ echo $JAVA_HOME
/usr/local/Cellar/openjdk#11/11.0.17
Viktors-MacBook-Pro:flutter_sandbox vintrino$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin:/usr/local/opt/coreutils/libexec/gnubin:/usr/local/opt/findutils/libexec/gnubin:/Users/vintrin/.nvm/versions/node/v15.14.0/bin:/Users/vintrin/Library/AndroidStudio/sdk/emulator:/Users/vintrin/Library/AndroidStudio/sdk/tools:/Users/vintrin/Library/AndroidStudio/sdk/tools/bin:/Users/vintrin/Library/AndroidStudio/sdk/platform-tools:/Users/vintrin/Library/AndroidStudio/sdk/cmdline-tools/latest/bin:/Users/vintrin/.toolbox/bin:/apollo/env/envImprovement/bin:/Users/vintrin/bin:/Users/nkondrat/vintrin-env/home_dir/python:/apollo/env/SDETools/bin:/apollo/env/GordianKnot/bin:/apollo/env/OctaneBrazilTools/bin:/apollo/env/envImprovement/jdk1.8/bin:/Users/nkondrat/apps/phantomjs-2.1.1-macosx/bin:/apollo/env/AmazonAwsCli/bin/:~/.rodar/bin:/Users/nkondrat/vintrin-env/home_dir/js/cli:/Users/vintrin/software/flutter/bin
Viktors-MacBook-Pro:flutter_sandbox vintrino$
The Intellij project is set to use Android33 API
The SDK is set here in Intellij
And the SDK is said to be installed by Android Studio
Running the following from intellij terminal to check java installation
Viktors-MacBook-Pro:flutter_sandbox vintrino$ $JAVA_HOME/bin/java --version
openjdk 11.0.17 2022-10-18
OpenJDK Runtime Environment Homebrew (build 11.0.17+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.17+0, mixed mode)
However for whatever reason when IntelliJ builds it tries to use java that doesn't exist at path:
/Users/vintrin/Library/AndroidStudio/sdk/bin/java
The flutter doctor command is happy for android
mac> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.3.10, on macOS 11.4 20F71 darwin-x64, locale en-US)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
How do I resolve java not being found?
Related
Setting up Flutter on MacOS Ventura 13.2 on an M1 MacBook Air. I've installed everything to get [✓] except for flutter doctor unable to find a bundled jre in Android Studio. I have found some other questions on this site, but none helped.
alan#Alans-MacBook-Air ~ % flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.7.0, on macOS 13.2 22D49 darwin-arm64 (Rosetta), locale en-GB)
[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1)
[✓] Xcode - develop for iOS and macOS (Xcode 14.2)
[✓] Chrome - develop for the web
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] VS Code (version 1.74.3)
[✓] Connected device (2 available)
[✓] HTTP Host Availability
Here's the full output of the Android Studio section:
[!] Android Studio (version 2022.1)
• 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
✗ Unable to find bundled Java version.
• Try updating or re-installing Android Studio.
I have java installed:
alan#Alans-MacBook-Air ~ % java -version
java version "19.0.2" 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
alan#Alans-MacBook-Air ~ % /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
I also have my environment setup correctly, I think:
alan#Alans-MacBook-Air ~ % echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home
Some other questions suggest playing with symlinks in the jre folder in the Android Studio install, but I have no jre folder in there. There is however a jbr folder, which appears to contain an OpenJDK build. But I don't know how to get flutter to see/use it.
alan#Alans-MacBook-Air ~ % /Applications/Android\ Studio.app/Contents/jbr/Contents/Home/bin/java -version
openjdk version "11.0.15" 2022-04-19
OpenJDK Runtime Environment (build 11.0.15+0-b2043.56-8887301)
OpenJDK 64-Bit Server VM (build 11.0.15+0-b2043.56-8887301, mixed mode)
Installed all the components as required in the documentation. I think I've set environment and other parts up correctly.
UPDATE 2
While the suggestion in Update 1 would work, this is not a "script" interpreted in real-time, and rather part of the flutter binary (if I am not mistaken), so in order for this to work, one would have to compile the flutter binary again, I don't know how to do that right now (as I've never used flutter beyond the basics) and I can't certainly do it on my "work machine" where the Corporate eyes forbid everything that is fun.
In other words, use the symlink trick you found in this GitHub issue until the Flutter team releases an updated flutter that searches for the correct java Path in the newer versions of Android Studio.
And Jetbrains, please, stop renaming the java location every other year...
UPDATE 1
In the flutter sdk, there's a file called: android_studio.dart. (well there are various android related files, none "java" related, since it seems like Flutter treats Java as an "android thing" (judging by the fact that all java references and validations or checks are performed in android_ files).
This file is located in path/to/flutter/packages/flutter_tools/lib/src/android/android_studio.dart.
Inside it contains this to calculate the path to java:
final String javaPath = globals.platform.isMacOS ?
version != null && version.major < 2020 ?
globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
globals.fs.path.join(directory, 'jre');
In essence, if you add another entry like this:
globals.fs.path.join(directory, 'jbr', 'Contents', 'Home') :
So it ends up looking like:
final String javaPath = globals.platform.isMacOS ?
version != null && version.major < 2020 ?
globals.fs.path.join(directory, 'jre', 'jdk', 'Contents', 'Home') :
globals.fs.path.join(directory, 'jre', 'Contents', 'Home') :
globals.fs.path.join(directory, 'jbr', 'Contents', 'Home') :
globals.fs.path.join(directory, 'jre');
Then you can run flutter doctor and it may work.
I also removed the && version.major < 2020 part, just to ensure it was always run. Now I see:
[!] Android Studio (version 2022.1)
✗ Unable to find bundled Java version.
[✓] Android Studio (version 2021.3)
So... Two different Android Studio versions, the latest (the one with jbr instead of jre seems to work fine.
In Android Studio Electric Eel, the bundled Java was moved to /Applications/Android Studio.app/Contents/jbr/Contents/Home so you can set your $JAVA_HOME to point to that directly.
In Addition, if you're on macOS (as it looks like that's the case) remember macOS uses (for some Apple reason) a binary called java_home to set the JAVA installations.
You can find this binary in /usr/libexec/java_home.
It seems like the flutter plug-in may be looking for Java under the assumption that it's under the "old" jre instead of the "new" jbr folder. I don't know if this is hardcoded (and therefore needs a 'patch') or if it just reads the environment variable for JAVA_HOME.
Are you using Jetbrain Toolbox to manage Android Studio?
If so, my solution may work for you.
I'm also using M1Air, Flutter 3.7.0, Android Studio Electric Eel 2022.1.1
cd ~/Library/Application\ Support/JetBrains/Toolbox/apps/AndroidStudio/ch-0/{ YOUR_VERSION_OF_ANDROID_STUDIO }/Android\ Studio.app/Contents/
run ls and look for /jbr
run sudo ln -s jbr jre and flutter doctor
This solved my problem.
EDIT
Your version of Android Studio can be found at Jetbrain Toolbox -> Android Studio -> Settings(3 dots on the right) -> Configuration -> Install Location
Related Github Issue
How do i solve this ? I've downloaded Android Studio Preview on my M1 Mac as suggested
error after running flutter doctor
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, 2.3.0-24.1.pre, on macOS 11.4 20F71 darwin-arm,
locale fr-FR)
[✗] Android toolchain - develop for Android devices
✗ cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
[✓] Xcode - develop for iOS and macOS
[✓] Chrome - develop for the web
[!] Android Studio
✗ Unable to find bundled Java version.
[✓] VS Code (version 1.58.2)
[✓] Connected device (2 available)
why is it still not working ?
I've been using SDK Man for years to install, update and change java versions with simple commands. It will take care of the installation and environment variable setup as well.
Here is a simple guide for mac users
Once the sdkman is installed, you can use it from the commandline:
sdk ls java
It will return a table with all the available versions.
The cleanest choice is the lastest 'official' LTS version, where the vendor is Java.net and the current latest version is 11.0.11-open
Sdkman also helps you with a command sample at the bottom of the table, so for the current latest LTS openJDK, I would go with:
sdk install java 11.0.11-open
And that's all. Or if you have previously installed java versions (installed through other means) it is best to remove them.
Make sure you have a JDK installed (you can get it here) and your $PATH and $JAVA_HOME are set up correctly. These sources can really help:
https://mkyong.com/java/how-to-set-java_home-environment-variable-on-mac-os-x/#what-is-usrlibexecjava-home
http://www.sajeconsultants.com/how-to-set-java_home-on-mac-os-x/
https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm#JSJIG-GUID-5F4A0659-BFC5-4CB9-9920-D2DEABF29894
https://medium.com/notes-for-geeks/java-home-and-java-home-on-macos-f246cab643bd
In case you've already set them up, double check what's going on with your JAVA_HOME by pasting this in terminal:
echo $JAVA_HOME
It should output a path like this (the jdk version may vary):
/Library/Java/JavaVirtualMachines/jdk-16.0.2.jdk/Contents/Home
If it the path looks the same (or same with different java version), and you have also checked "where java", "java -version" etc, to make sure that the terminal recognises your java well and there is no other obvious java issue, that means that the only thing left is to run these commands one by one:
cd /Applications/Android\ Studio.app/Contents/jre
ln -s ../jre jdk
ln -s "/Library/Internet Plug-Ins/JavaAppletPlugin.plugin" jdk
Now if you run "flutter doctor -v", you should see no java errors and something like this instead of the previous error:
• Java binary at: /Applications/AndroidStudio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
Hope this helps! It solved the issue for me :)
These answers might help too:
Unable to find bundled Java version. MacBook Air M1
Unable to find bundled Java version on Flutter
Flutter-Unable to find bundled Java version(flutter doctor), after updated android studio Arctic Fox(2020.3.1) on M1 Apple Silicon
Everything was working fine 4 days ago - I did an update and the licenses stopped going through... what I did so far.
the tools obsolete thing is checked -> does not work
flutter doctor --android-licenses -> does not work
sdkmanager --licenses -> did not work
uninstall and reinstall android at least 3 times -> did not work
downloaded manually cmdline-tools folder and put in the Sdk folder -> did not work
delete folder tools and replaced with new one -> did not work
flutter doctor
[!] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
X Android license status unknown.
flutter doctor --android-licenses
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlSchema
Flutter 1.17.0 • channel stable • https://github.com/flutter/flutter.git
Framework • revision e6b34c2b5c (7 days ago) • 2020-05-02 11:39:18 -0700
Engine • revision 540786dd51
Tools • Dart 2.8.1
$ java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
Android Studio 3.6.3
I encountered the same problem just recently. I solved mine with the ANDROID_HOME path in the Environment Variables.
my solution for the licenses - after 6 days...
uninstall everything JAVA AS WELL.
then reinstall javaSE (jdk8) and reinstall everything openJDK11 as JAVA_home path.
flutter doctor will ask you to do --android-license .
I am trying to launch a virtual device emulator on NativeScript Sidekick and keep getting
"[19-04-16 12:57:55.059] Failed to start virtual device iPhone 6s. Errors:
"Unable to execute avdmanager, ensure JAVA_HOME is set and points to correct directory""
I am using MacOS.
What else should I check and why would avdmanager be needed to run an IOS simulator?
I have verified JAVA_HOME is set.
uss-c02nq3veg3qp:~ jt7$ which java
/usr/bin/java
uss-c02nq3veg3qp:~ jt7$ java --version
java 11.0.2 2019-01-15 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+9-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+9-LTS, mixed mode)
I also have Android Studio and XCode installed (and xcode command line tools) and and verified my AndroidHome env variable is set.
uss-c02nq3veg3qp:~ jt7$ echo $ANDROID_HOME
/Users/jt7/Library/Android/sdk
The adp command successfully runs.
Here is my .profile file
JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-11.0.2.jdk/Contents/Home/
ANDROID_SDK_ROOT=/usr/local/share/android-sdk
export JAVA_HOME
export ANDROID_SDK_ROOT
export ANDROID_HOME=/Users/jt7/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH/:$ANDROID_HOME/platform-tools
I would expect the emulator run as it does successfully from Android and XCODE (for Android and IOS, respectively). Why wouldn't it from NativeScript Sidekick?
I had the same situation. Running tns doctor helped me. Under the hood this command uses homebrew to reinstall almost everything on your machine (🤦♂️), but at least nativescript sidekick starts to work and build the code on emulators locally.
I'm working on MacOS and just starting with react-native.
One of the first steps to get started is to run: react-native run-android or react-native run-ios. But I'm getting this error:
react-native run-android
Result:
Scanning folders for symlinks in /Users/ric/myprojs/albums/node_modules (6ms)
Starting JS server...
Building and installing the app on the device (cd android && ./gradlew installDebug)...
FAILURE: Build failed with an exception.
* What went wrong:
Could not determine java version from '9.0.1'.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
Could not install the app on the device, read the error above for details.
Make sure you have an Android emulator running or a device connected and have
set up your Android development environment:
https://facebook.github.io/react-native/docs/android-setup.html
This is what I get when I run java --version:
java --version
Result:
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
mbp:albums ric$ java --version
java 9.0.1
Java(TM) SE Runtime Environment (build 9.0.1+11)
Java HotSpot(TM) 64-Bit Server VM (build 9.0.1+11, mixed mode)
Edit
My javac version:
javac --version
Result:
javac 9.0.1
Any idea on how to fix this?
In your PROJECT_PATH/android/gradle/wrapper/gradle-wrapper.properties file, update your distributionUrl to the following:
distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-all.zip
See related gradle distributions documentation
Really the fastest way to get around this error is to use JDK 8. Except when you really need to use JDK9.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Don't forget to change your enviroment variable JAVA_HOME to the new JDK version!
Make sure that you have JDK8 installed and then set JAVA_HOME into JDK8
for example:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_151.jdk/Contents/Home
or use .bash_* files to set this variable
vi ~/.bash_profile
Then add the following lines:
export ANDROID_HOME=$HOME/Library/Android/sdk
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools
export JAVA_HOME=$(/usr/libexec/java_home -v 1.8)
Now source the file to make the above changes effective in the current shell:
source ~/.bash_profile
On MacOS, I ran the following commands:
brew cask uninstall java
brew tap caskroom/versions
brew cask install java8 "or just brew cask install java to install latest version"
I was getting this error, but for a more recent version of Java - 10.0.2.
To fix my error, I followed the steps mentioned by #Blacktoviche in this Github issue: https://github.com/facebook/react-native/issues/17688
When I opened the android folder inside my project via Android Studio, I was prompted with Android Gradle plugin update recommended. At the time, I was following a slightly outdated tutorial that told me to click Don't remind me again for this project.
However, as #Blacktoviche recommended in the github issue linked above, sometimes it's necessary to update the Gradle plugin. After updating, I also had to click Install Build Tools 27... and sync project (I don't remember the exact version).
After I followed these steps, I was able to successfully run my react native app on the Android Studio emulator.
Hope this helps someone!
---- December 2018 --- keep attention ---
React Native does not work with Java versions higher than 8, so you need to uninstall your 9.0.1 version. To do so, execute the following commands:
cd /Library/Java/JavaVirtualMachines/
ls -l
Identify the folder containing your Java Version, then remove it
sudo rm -rf jdk.x.x_xxx.jdk
After that you can download and install java 8 from oracle again. Refer to jdk8 download page
If you are using windows; Make sure you add your jdk path to the Environment path variable.
Then open your android folder from your react native project into android studio. It will update necessary things for you automatically.
I usually get this error when I forget to build the project using Android Studio. A simple sync and upgrading Gradle will do the work.
I solve this by downgrading my JDK to 8.
On Ubuntu, you should run these command lines in the terminal:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt install oracle-java8-installer
sudo apt install oracle-java8-set-default