Flutter doctor results with "cmdline-tools component is missing" - java

I have tried the answers at here & here to no avail.
After installing Android Studio & Flutter on Windows 10, when I run flutter doctor, I get the following:
[√] Flutter (Channel stable, 2.5.0, on Microsoft Windows [Version 10.0.19043.1202], locale en-US)
[X] Android toolchain - develop for Android devices
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
[√] Chrome - develop for the web
[√] Android Studio (version 2020.3)
[√] VS Code (version 1.60.0)
[√] Connected device (2 available)
Opening Android Studio > SDK Manager > Android SDK > SDK Tools uninstalling and re-installing Android SDK Command-line Tools (latest) has no effect.
I have also added <pathToSDK>\tools\bin, <pathToSDK>\platform-tools\, and <pathToSDK>\cmdline-tools\latest\bin to the user PATH environment variables.
Following the flutter instructions and running <pathToSDKManager> --install "cmdline-tools;latest" (Which for me is located in <pathToSDK>\cmdline-tools\latest\bin) results with:
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.
I haven't been able to find any documentation on this other than that I need to install some version on Java and add it to my path. The https://flutter.dev/docs/get-started/install/windows page mentions "Make sure that you have a version of Java 8 installed and that your JAVA_HOME environment variable is set to the JDK’s folder." and then states "Android Studio versions 2.2 and higher come with a JDK, so this should already be done." but doesn't elaborate further.
Opening Android Studio and going to File > Project Structure > Project > Project SDK I can see that Android Studio already recognized several versions of Java installed:

You can follow the below steps in order to ensure proper working of your flutter project:
Your sdk manager should look something like this:
1. Installing Android SDK Command-line Tools in Android Studio:
Preferences > Appearance & Behavior > System Settings > Android SDK > SDK Tools >
Install these 3 tools:
Android SDK Command-line Tools (latest)
Android SDK Build Tools 31
Android SDK Platform tools (latest version 31)
Make sure every tool is the same latest version in order to avoid any errors as there might be new updates later on.
Also make sure to Accept Android Licences by running below command in your cmd:
flutter doctor --android-licenses
If anything above didn't work out make sure you have set the proper JDK/JRE locations in environment variables in system settings of windows:
Add below path in your System environment path variable for user variable as well as your system variable:
C:\Program Files\Java\jdkXXXXX\bin
Here, XXX is your version, and this should be added in your sys var and user both
C:\Users\Neha\AppData\Local\Android\Sdk\tools
C:\Users\Neha\AppData\Local\Android\Sdk\build-tools
C:\Users\Neha\AppData\Local\Android\Sdk\platform-tools
The above three paths should be added in your user variable path. Check the two screenshots attached below for proper path settings.
I have added android studio's tools path also so do that as I have done in screenshot.
This one is for user variable path:
This one is for system variable path:
Follow source to learn more about setting the path for java.

Just Install them:
Android SDK Command-line Tools (latest)
Android SDK Build Tools 31
Android SDK Platform tools (latest version 31)
run: 'flutter doctor --android-licenses'
after run 'flutter doctor' again.
And boom. it will work.

In the screen you've shown, just use "Android Studio default JDK" (or any other JDK 11).
Settings > Build, Execution, Deployment > Build Tools > Gradle > Gradle JDK.
You'd also need to setup the same path as JAVA_HOME environmental variable, as well as ANDROID_HOME. In Windows, these can be added below Settings > Advanced System Settings > Environmental Variables. Flutter needs these set up to find the CLI tools ...
and the problem might not be the CLI tools themselves, but that it doesn't know about the Java SDK or Android SDK at all.

If you are installing Flutter without Android Studio.
Run this command in your Android/bin folder directory where you have your sdkmanager.bat file.
In my case its C:\Android\bin>.
type this command
sdkmanager.bat --install "cmdline-tools;latest --sdk_root=../
This worked for me and I hope it will work for you too.

If you have installed Flutter without Android Studio. Run this command in your Android/bin folder directory where you have your sdkmanager.bat file. In my case its C:\Android\bin>
sdkmanager.bat "cmdline-tools;latest" --sdk_root=../

Related

Java SDK 11.0 or above is required when using .NET 6 or higher

I've installed .NET 6 (version 6.0.100-rc.1.21458.32) and Visual Studio 2020 Preview (although it might be not a prerequisite).
I am trying to debug a hello-world application but I am getting a build error regarding Java.
C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\31.0.100-rc.1.12\targets\Microsoft.Android.Sdk.Tooling.targets(20,5): error XA0031:
Java SDK 11.0 or above is required when using .NET 6 or higher.
I've installed Java 17 setting Path as well as pointing to the Java Development Kit Location in Visual Studio settings (tools->options->Xamarin->Android Settings). Because that didn't work I've set the JDK location to Microsoft's openjdk, but it still doesn't work.
What's wrong here?
Installing Microsoft's OpenJDK 11 did the job for me.
You may notice that Visual Studio installs a version of Microsoft
OpenJDK, however, you need to install the Microsoft OpenJDK 11
When I installed VS2022 preview 4, my configuration became C:\Program Files\Microsoft\jdk-11.0.10.9-hotspot
This can be fixed for you if you run the maui-check command (if you installed that component during visual studio installation).
If you don't have the maui-check tool, you can get it by running the dotnet tool install -g Redth.Net.Maui.Check command
Maybe you skipped a step during installation and that's why you get the error.
For those who have the same problem in Jetbrains Rider :
Install OpenJDK 11 (Microsoft's OpenJDK 11 seems to be better) as mentioned by #themelis
Press Ctrl + Shift + A and search MSBuild global properties or go to File > Settings > Build, Execution, Deployment > Toolset and Build
Edit the MSBuild global properties and add the following property:
Name: JavaSdkDirectory
Value: {OpenJDK installation directory} (mine is C:\Program Files\Microsoft\jdk-11.0.16.101-hotspot)
Save and Enjoy!
Visual Studio for Mac
Here's how I got it working on macOS with Visual Studio for Mac.
Install Microsoft Open JDK
On macOS, install the Microsoft Open JDK using HomeBrew:
brew install --cask microsoft-openjdk
Configure Visual Studio for Mac
In Visual Studio for Mac, select Visual Studio -> Preferences.
In the Preferences window, navigate to SDK Locations -> Android -> Locations.
In the Java SDK (JDK) Location: text box, enter the following:
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
Click OK

Windows version error when installing Android Studio 3.1 Preview 2

I am getting the following error when trying to install Android Studio 3.1 Preview 2 on Windows:
Error: CreateProcess error=216, This version of %1 is not compatible
with the version of Windows you're running. Check your computer's
system information and then contact the software publisher.
I have tried to install the following - but still didn't help:
Install jdk1.8.
I also tried the following in Android Studio:
File->Project Structure->SDK Location (select your directory where the JDK is located, by default Studio uses embedded JDK) -> Click OK
But for some reason this produces error=216.

Android Studio and JRE on OS X

Installing AndroidStudio 2.0 on OS X El Capitan: if I install JRE 7 from http://www.oracle.com/technetwork/java/javase/downloads/jre7-downloads-1880261.html, I will not receive Public Updates; if I install JRE 8, Android Studio complains that it cannot use secure connection to receive upgrades:
Is there a way to convince AS that JRE 8 is not JRE 6? If impossible, which compromise is preferable: downgrade to JRE 7 and establish secure connection for Android Studio upgrades, or keep the latest JRE and wait for Android Studio fix?
From the documentation, by default Android Studio is launched from java 6: http://tools.android.com/tech-docs/configuration/osx-jdk
As it is mentioned you can export an env variable to indicate Android Studio what jdk to use :
export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk<version>.jdk
In order to keep this env variable accessible from the GUI, you can add the following line to your ~/.profile file :
launchctl setenv STUDIO_JDK /Library/Java/JavaVirtualMachines/jdk<version>.jdk
Hope it helps.
Another solution for OSX: go to the Applications folder, right click on Android Studio, choose "Show Package Contents".
Open the Info.plist file. Locate the JVMVersion key, and set the string value you need.
In my case, I needed to be 1.7 and up to be able to run the RoboVM plugin, and the value was 1.6*,1.7+, so I left it only on 1.7+.
Restart Android Studio and it should be using the version of the JVM you need.
This works if you have root access on your Mac.
refers to Android Studio IDE with private jre/jdk? OSX
In Android Studio 2.1.2 and below,the default settings is '1.6*,1.7+'.
In the latest version of Android Studio(2.2 Preview 7),the default settings is '1.8*,1.8+'.

Android Studio could not detect SDK

After installing Android SDK, Gradle and JDR, JRE on Linux, Android Studio could not detect SDK in /usr/lib/jvm/jdk1.8.0_11.
IntelliJ IDE does not have any problem and everything is OK. But android studio displays this error:
No Android SDK found. Please configure an Android SDK.
the path of the SDK is the same as for IntlliJ IDE.
.bashrc content:
export JAVA_HOME=/usr/lib/jvm/jre-8-oracle-i586
Other Information:
sudo update-alternatives --config java
[sudo] password for tux-world:
There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/jre-8-oracle-i586/bin/java 317 auto mode
* 1 /usr/lib/jvm/jdk1.8.0_11/bin/java 1 manual mode
2 /usr/lib/jvm/jre-8-oracle-i586/bin/java 317 manual mode
How to resolve this problem?
Have you downloaded any SDK from Android SDK Manager? or you just installed the SDK manager?

Android Studio Emulator - Java instance does not support 32 bit JVM

I am running android studio on a Mac os x maverick. I have installed the 64bit JDK. When I run the emulator I get the message
Error:Abnormal build process termination:
Error: This Java instance does not support a 32-bit JVM.
Please install the desired version.
in android studio.
java -version
returns
version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
and
$JAVA_HOME
points to
/Library/Java/JavaVirtualMachines/jdk1.7.0_51.jdk/Contents/Home
So every thing seems to be fine. What could possibly be wrong?
Update:
I still had an old jdk1.6 lying around on my mac. When removing it Android Studio was asking to install Java 6 again. So apparently Android Studio needs Java 6 to compile (as confirmed by Andrew in the comment of this question). Hoping that it would install the x64 version I let it install Java 6. However I still wasn't successful afterwards. I neither could find Java 6 for Mac OS X 64 Bit. Any hints on that?
Android Studio can run on whatever it needs, but the error seems to be pointing to the SDK that the project is using. To check what your project is using, go into Project Structure > Project Settings > Project. You should now see the Project SDK. It should say something like "Android API ## Platform (java version "1.7.[current version number]"). If it doesn't say 1.7.[current version number], then it probably needs to be updated.
Here's what you can do to update it:
In Project Structure > Platform Settings > SDKs, click the "+" button to add a new SDK.
In the pop-up, go into your Android SDK folder and click "Choose"
Another pop-up will appear asking for which SDK and JDK you want to use. Choose any Android SDK and the 1.7 JDK.
Go to Project Structure > Project Settings > Project and change your Project SDK to the one you just created. You should see the name of the SDK with the new Java version that you installed.
I am not sure but I think that sometimes the error is actually stating a falsehood, and is misleading.
I agree with #Maxwell inasmuch as the problem is a mismatch between the JDK configured for the project and the JDK that IntelliJ is running under.
The specific problem I encountered was Running IntelliJ 13.1.1 with 1.6.0_65 ... x86_64 while compiling a project configured with a Java 7 x64 JDK. Reconfiguring the project to an x64 Java 6 JDK put out the fire.
I resolved this issue by doing the following:
Go to File -> Project Structure... -> Platform Settings -> SDKs
Select the SDK listed
Click on the ' - ' to remove it.
Restart Android Studio
Go to File -> Project Structure -> Platform Settings -> SDKs
Select the SDK listed
Click on the ' + ' to add it (follow path to your JDK HOME)
Restart Android Studio, and re-Build your Project.

Categories