Android Studio shows an error when trying to use Embedded JDK instead of a custom install - android-studio

After I updated to Android Studio 2.3, I haven't been able to use the embedded JDK. When I try to build the project, I get errors like this:
Error:The newly created daemon process has a different context than expected.
Java home is different.
Expecting: 'D:\Development\IDE\AndroidStudio\jre' but was: 'C:\Program Files\Java\jre1.8.0_121'.
Please configure the JDK to match the expected one.
Open JDK Settings
But the JAVA_HOME environment variable isn't defined, but I can still use the normal JDK any problems, so I don't believe that's a problem. Where does Android Studio find the JAVA_HOME that prevents me from using the embedded JDK?
I tried uninstalled the system JDK to get it to work, and I updated java, which lead to it pointing to the JRE. I then reinstalled the JDK and when I point to it, it works fine. But I want to use the embedded JDK. Any ideas?
I have tried setting JAVA_HOME in gradle.properties, as linked in comments, but it still shows the error.
The line I added was:
org.gradle.java.home=D:/Development/IDE/AndroidStudio/jre
It should make the embedded JDK work (and change JAVA_HOME in the IDE) but it doesn't. It still leads to the same error mentioned at the top of this post.
In the snippet it says jre, and that was because when I copied it, I had just uninstalled the JDK. Updating the JDK and Java resulted in JAVA_HOME being set to the JDK location, but it isn't defined as an environment variable. I tried deleting the JDK table in Android Studio's config folder, but it did not work.
And what it looks when I set the JDK to be the embedded:

Try to reset your path of your updated JDK. and check it again. May be it will help you. Also clear your android studio temp cache and all.

I fixed this issue by uninstalling all the jdk installation & updates then reinstall only one jdk and assure its env. variables
I do not have a solution but I have the same problem it happens as the android studio opens from java_home/jre thence all JVMs that will fork next will come from this path, while your system varible tells Gradle to get his java.exe from JAVA_HOME
I tried to make gradle read from jre but it falied also i tried to make android studio open from java_home/bin but it falid also

I had the exactly same issue with embedded JDK which was working on Android studio version 2.2.3 and when I updated then every time studio prompts JRE not found then I added system JDK path in project folder and now Whole Android studio hanging and I switched back to Android studio 2.2.3. It seems Android studio 2.3.1 is buggy release.

It seems ,There are some miss match of JDK version.
So Try this:
First Uninstall all Jdk/jre and Android Studio.
Clear temp/prefetch etc.
then Simply Install latest version of Android studio.
Remember: Don't install any other JDK/jre and make sure that your system have proper internet connectivity.All missing file automatically downloaded.
I had try this already and it was work for me .I hope it will also work for you.

I must say the AS has too many trouble in environment settings. There are some concepts we need to know.
AS default java runtime environment itself ,as shown below.
AS default java runtime environment itself.
System has another Java_home as shown below.
System's JDK version
Then problem is coming , what will happen when the system's JDK version doesn't match the AS's JDK version?
i.
java.lang.UnsupportedClassVersionError
ii.
gradle failure:certification ...
iii. There are some other error I couldn't remember now.
Solution:
If your AS update to latest version,you should update your Gradle to latest version,and make sure your system's JDK is match AS's JDK version. At least, your idk version update to more than JDK1.8.0. When you do all of this ,try to restart your AS ,if does works ,try to restart your computer.
Extra:
The proxy software has some influences when Gradle sync, if there are any tips about certificate ,try to close proxy software and try again.

Related

Newest Android Studio 2021.3.1.17 release gets stuck on launch screen

I've installed the newest version of Android Studio with the installer on my Windows 10, currently it's version 2021.3.1.17 Dolphin.
Upon launching it, the splash screen appears and the little bar loads to the end and then it gets stuck indefinitely on that screen. All I'm seeing is this:
I've tried the following stuff already:
Completely uninstalling Android Studio, making sure all the files have been removed correctly before re-installing it (except the JetBrains folder, since I have other JetBrains stuff in it)
Re-Downloading the installer from the official Android Studio Website to make sure it was not corrupted.
Run as Administrator.
Was previously installed on a non-primary drive D:/, and I've also tried installing it on my primary drive C:/ just in case, same issue with C:/ installation too.
Ran studio.bat to see any errors, however, I'm assuming that bat file itself is buggy. It tells me that it does not find any JRE or JDK installation within the path. So to fix it I've set the newest Oracle JDK19 as my JAVA_HOME and the /bin accordingly, however, the studio.bat will then continue a long java error which seems honestly unfixable, so I won't even bother posting it here. Me setting the path shouldn't even be necessary, as Android Studio comes bundled with a JDK... and it should be using that one anyway.
So I'm out of things to try. I cannot make it work. My only lead was the Java error, but according to some Google search, I shouldn't even have to deal with it as it comes bundled with Android Studio. Looking into the files, there is indeed a jre folder within the Android Studio installation. Is it not using that one? What could be the reason that it is not using it if that is the case?
So, I was able to fix it myself after trying a few hours more. I've had also other Java installations (Java JDK 8, JDK 19) that interfered somehow with Android Studio. I've uninstalled everything related to Android Studio and I've uninstalled every Java version I had.
Additionally, I've removed every reference to Java or Android Studio from all of my system and environment variables. Also removed a path to Android SDK that was within my system variables.
After rebooting and installing Android Studio, it worked. Haven't installed any Java version so far, so not sure if the issues will return if I install my Java versions again.

How can I use gradle installed in WSL alongside Android Studio installed on Windows

I've recently had to start developing a Micronaut project in Android Studio instead of IntelliJ IDEA Ultimate. I'd assumed that because they share the same base this would be fine but when I load up my project I get this (the project is held in the wsl filesystem and all development has been using WSL with IDEA):
14:07 Project [name] is using the following JDK location when running Gradle:
//wsl$/Ubuntu-22.04/usr/lib/jvm/java-11-openjdk-amd64
Using different JDK locations on different processes might cause Gradle to
spawn multiple daemons, for example, by executing Gradle tasks from a terminal
while using Android Studio.
More info...
Select a JDK
Do not show this warning again
It's unclear why this is happening, when I click 'Select a JDK', what is selected is the JDK installed on WSL that IntelliJ is using, likewise it is pointed at the same directory where my gradle properties is kept.
I'm not sure where to go with this, my guess would be maybe Android Studio is trying to run a gradle or java instance that's not the WSL one (I think it installs it's own alongside) and that's the issue but the settings would imply otherwise. Does anyone know what might be happening?
Thanks!

Android Studio ArticFox compiling fine but showing red errors everywhere

I have a multi module Android Compose project. One module is an android app, others are android libraries or kotlin libraries. I'm running AS Artic Fox 2020.3.1 Beta 5 on MacOS 11.4 Big Sur.
After a library upgrade (probably AGP to use compose, I don't remember when exactly) Android Studio started to show syntax errors everywhere, both in .kts and .kt files.
Compilation and execution are working fine, only those weird JDK errors are displayed.
Here are some examples :
in a .kt file from a kotlin library module, in a .kts file from the buildSrc module
It seems that there is an error with the JDK somewhere, but I don't understand how to fix it.
I Googled/StackOverflowed before posting here and I already tried :
to check the JDK used Project Structure > SDK Location > Gradle. It is using the Embedded JDK 11.0.10
to reinstall AS using Jetbrains Toolbox
to invalidate cache and restart
to clone my project again
to delete ~/.gradle
But none of those actions helped...
Thanks in advance !
Update 22/07
I tried to create a new empty Compose project with .kts support, but no luck, everything is in red
Because of a bug preventing to update, I updated manually to RC_1. Here is my current setup.
I tried to change from Embedded JDK to a separately installed OpenJDK 11 and reimport but not luck (#alexey-belkov suggestion)
I checked the logs but found nothing obvious (#andy suggestion)
ℹ️ Finally I tried to create a new empty Android project with only .gradle support, and no errors ! Could it be a kotlin script plugin problem ?

Android Studio re-installation from 1.x.x to 2.3.3 version

1) I re-installed Android Studio from 1.x.x to 2.3.3 version. The installation guide said the difference is too big and suggested first the previous version be uninstalled. It appears uninstallation still leaves the previous Studio structure and AndroidStudio and SDK directories still are kept in their places. Then installation built a new version at locations AndroidStudio1 and SDK1.
But when I look in Settings for SDK location it points to SDK rather than to SDK1. Could it be a problem?
2) When trying to "Check out project from Version Control > GitHub" I receive the following error "Cannot run program "git.exe": CreateProcess error=2, The system cannot find the file specified".
The sdk directory name is not a problem. You can always change to any sdk version you want
U need to install git first. Have you installed git?

Android Nougat requires the IDE to be running with Java 1.8 or later [duplicate]

This question already has answers here:
Android N requires the IDE to be running with Java 1.8 or later?
(17 answers)
Closed 6 years ago.
Inspite of having JDK 8 installed, I'm getting this error. What can the issue be?
Check installed java version, it should be 1.8 or later.
MBP-Vitaliy:~$ java -version
java version "1.8.0_92"
Java(TM) SE Runtime Environment (build 1.8.0_92-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.92-b14, mixed mode)
Check java version in Android Studio.
In Mac OS X: Android Studio -> About Android Studio.
Where JRE should be 1.8 or later.
If you have another, In Mac OS X go to Applications folder find AndroidStudio.app and click Show content, then find in Content folder Info.plist file and change JVM VERSION to 1.8 manually.
<key>JVMVersion</key>
<string>1.8</string>
Restart Android Studio.
for mac users #Vitaliy Movchan answer works.
for windows users (who has to set JAVA_HOME in their operative system):
Install the JDK 1.8 and note the destination path, usually C:\Program Files\Java\jdk1.8.0_xx
Right-click My Computer and select Properties.
Click the Advanced System Settings link in the left column.
In the tab Advanced click Environment Variables
Create or modify the variable JAVA_HOME.
Enter the variable value as the installation path for the Java Development Kit.
You can still get the layout rendered during design time in the IDE if you choose Android version 23 (Marshmallow) rather than version 24 (Nougat).
This isn't a long-term solution, but for most purposes it should be good enough. You can always see the actual Nougat layout by running your app in the Android emulator.
Add JVMVersion 1.8*, 1.8+ to info.plist of android studio app and also check for default java version
I had the same problem, in my system i have installed 3 jdks.
jdk1.6, jkd1.7, and jdk1.8.
I am working on some projects which requires jdk 1.7 so i can't change JAVA_HOME.
So i have found another solution by tell android studio which JAVA_HOME needs to be used.
So i just edit studio.sh file and added JAVA_HOME variable.
JAVA_HOME = /usr/lib/jvm/java-8-oracle/
studio.sh file
After Restart android-studio started pointing to jdk 1.8.
Hope this will help.

Resources